How to write on multiple lines in a QMessageBox in QtCreator?

sunset picture sunset · Aug 1, 2011 · Viewed 8.3k times · Source

I would like to have in a message box the following lines:

name:
surname:
data:
test:

After each : I'll programmatically fill the line. I would like to ask how can I have this structure in a QMessageBox. It is possible?

I am a beginner in Qt Creator. Currently I learned to do this:

QMessageBox noc;
            std::string s= "hello1";
            QString er = s.c_str();
            noc.setText(er);
            noc.exec()

Answer

Donotalo picture Donotalo · Aug 1, 2011
QString str;

str = QString("name: %1\nsurname: %2\ndata: %3").arg(...).arg(...).arg(...);
QMessageBox::information(0, "Title", str);

Take a look at QMessageBox::information() and QString::arg().