【发布时间】:2013-12-20 18:49:06
【问题描述】:
我目前正在使用 QT 中的 QStrings,似乎无法理解为什么以下代码不适合我。
#include <QCoreApplication>
#include <QDebug>
#include <QString>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString test;
int x = 5;
test.append("This is a test of the Arg Function %1").arg(x);
qDebug() << test;
//should output This is a test of the Arg Function 5
return a.exec();
}
我得到的输出是:
这是对 Arg 函数 %1 的测试
显然我期望值 5 来代替 %1,我在这里遗漏了一些明显的东西吗?
【问题讨论】:
-
我觉得应该是:
test.append(QString("This is a test of the Arg Function %1").arg(x)); -
编译器没有警告你
test.append("This is a test of the Arg Function %1").arg(x);?