如何在QtCreator中编写多行QMessageBox

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

本文关键字:QMessageBox QtCreator      更新时间:2023-10-16

我想在消息框中有以下几行:

name:
surname:
data:
test:

在每个:之后,我将以编程方式填充该行。我想问我怎么能在QMessageBox中有这个结构。有可能吗?

我是Qt Creator的初学者。目前我学会了这样做:

QMessageBox noc;
            std::string s= "hello1";
            QString er = s.c_str();
            noc.setText(er);
            noc.exec()
QString str;
str = QString("name: %1nsurname: %2ndata: %3").arg(...).arg(...).arg(...);
QMessageBox::information(0, "Title", str);

看一下QMessageBox::information()和QString::arg()

只需在每个字符串的末尾加上"n"…

QMessageBox noc;
QString er = tr("name: %1nsurname: %2ndata: %3ntest:%4").arg(...);
noc.setText(er);
noc.exec();