问题描述
我是 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那么你可以把它转换成一个,
//
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);
//
连接 QStrings 可以直接工作,因为运算符 + 过载
QString pdfPath="C:\here!";
QMessageBox::question(this,"The Report is in Path: " + pdfPath + "saved,QMessageBox::Yes | QMessageBox::No);