1

我是 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 +“已保存,你想打开它吗”)但它不起作用。先感谢您 :)

4

1 回答 1

1

如果 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, "Report", "The Report is in Path: "  + pdfPath + "saved, do you want to open it", QMessageBox::Yes | QMessageBox::No);
于 2021-01-20T09:12:42.953 回答