String and Variable combination

129 Views Asked by At

i m a beginner in c++ and i have a question. how can i combine a variable and a string in the folowing line.

QMessageBox::Question(this,"Report", "the Report is in Path: "  + pdfPath + "saved, do you want to open it", QMessageBox::Yes | QMessageBox::No);

pdfPathis my Variable where the path of my pdf-file is saved.

I tried this, ("the Report is in Path: " + pdfPath + "saved, do you want to open it") but it does not work. Thank you in advance :)

1

There are 1 best solutions below

0
On

if pdf path is not a QString then you can to convert it into one,

//
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);
//

concatenating QStrings works straigh forward cos the operator + is overloaded

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);