gpt4 book ai didi

c++ - 如何在 Qt QMessageBox 中添加变量值?

转载 作者:行者123 更新时间:2023-11-28 00:02:14 25 4
gpt4 key购买 nike

printf("This machine calculated all prime numbers under %d %d times in %d 
seconds\n", MAX_PRIME, NUM_OF_CORES, run_time);

我希望此输出打印在 QMessageBox 文本框中。

我浏览了 QMessageBox 文档,但没有找到任何有用的信息。

最佳答案

QMessageBox 没有任何用处,因为这不关它的事——它只是在您传递字符串时显示它们。但是,QString 确实提供了使用 arg 方法格式化数据替换占位符的方法:

QMessageBox::information(parent,
QString("This machine calculated all prime numbers under %1 %2 times in %3 seconds")
.arg(MAX_PRIME)
.arg(NUM_OF_CORES)
.arg(run_time), "Message title");

http://doc.qt.io/qt-5/qstring.html#argument-formats

http://doc.qt.io/qt-5/qstring.html#arg

关于c++ - 如何在 Qt QMessageBox 中添加变量值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37983265/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com