<分区>
我试过使用Qt4.8文档中给出的例子:
#include <QCoreApplication>
#include <QString>
#include <iostream>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString str;
str = "%1 %2";
str.arg("%1f", "Hello"); // returns "%1f Hello"
std::cout << str.toStdString().c_str() << std::endl;
str.arg("%1f").arg("Hello"); // returns "Hellof %2"
std::cout << str.toStdString().c_str() << std::endl;
return a.exec();
}
然而这输出:
%1 %2
%1 %2
两次。我已经在 Windows 7 和 Ubuntu 上使用 QtCreator 和命令行尝试过这个。我检查过我有
QMake 版本 2.01a
在/usr/lib/x86_64-linux-gnu 中使用 Qt 版本 4.8.1
在 Windows 中:
QMake 版本 2.01a
在 C:\qt\4.7.0\lib 中使用 Qt 版本 4.7.0
我什至检查了我的源文件中的非 ascii 字符,例如“%”符号是正确的。请告诉我为什么这不起作用!
这是我正在使用的 PRO 文件:
QT += core
QT -= gui
TARGET = testarg
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp