c++ - 如何在 QtCreator 的 QMessageBox 中写多行?

标签 c++ qt qt-creator qmessagebox

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

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: %1\nsurname: %2\ndata: %3").arg(...).arg(...).arg(...);
QMessageBox::information(0, "Title", str);

看看QMessageBox::information()QString::arg() .

关于c++ - 如何在 QtCreator 的 QMessageBox 中写多行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6895681/

相关文章:

c++ - 在 Windows 上交叉编译 XZ-5.X.X

qt - 通过 QDBus 发送 float

python - QProcess 将参数传递给 python 脚本

c++ - QtCreator 中的 "Fatal Error C1083: Cannot open include file"

c++ - 如何暂停这个opengl程序?

c++ - 在线程之间重定向标准输入/输出

c++ - 在递归函数中声明一个静态变量。堆栈溢出

c++ - 在类中记录私有(private)结构

c++ - 在两个不同的头文件中声明相同的命名空间,然后将它们包含在一个 cpp 中

c++ - 当/MT 和/MD 都需要时怎么办?