我是c++的初学者,我有一个问题。如何在下一行中组合变量和字符串
QMessageBox::Question(this,"Report", "the Report is in Path: " + pdfPath + "saved, do you want to open it", QMessageBox::Yes | QMessageBox::No);
pdfPath
是我的变量,其中保存了我的pdf文件的路径。
我试过了,("报告在路径中:"+ pdfPath + "已保存,你要打开它"),但它不工作。提前谢谢你:)
如果pdf路径不是QString,那么您可以将其转换为QString,
//
std::string pdfPath="C:here!";
QMessageBox::question(this, "Report", "The Report is in Path: " + QString::fromStdString(pdfPath) + "saved, do you want to open it", QMessageBox::Yes | QMessageBox::No);
//
连接qstring直接工作,因为操作符+是重载的
QString pdfPath="C:here!";
QMessageBox::question(this, "Report", "The Report is in Path: " + pdfPath + "saved, do you want to open it", QMessageBox::Yes | QMessageBox::No);