试验1:
#if _MSC_VER >= 1600
#pragma execution_character_set("utf-8")
#endif #include <QtWidgets/QApplication>
#include <QtWidgets/QLabel>
#include <QtCore/QObject> int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QLabel w;
w.resize(, );
w.setWindowTitle(QStringLiteral("你好!"));
w.setText(QObject::tr("你好"));
w.show();
return a.exec();
}
结果如下:
试验2
去掉前面的
#pragma execution_character_set("utf-8")
#include <QtWidgets/QApplication>
#include <QtWidgets/QLabel>
#include <QtCore/QObject> int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QLabel w;
w.resize(, );
w.setWindowTitle(QStringLiteral("你好!"));
w.setText(QObject::tr("你好"));
w.show();
return a.exec();
}
结果如下:
结论:
在VS中, 使用
#if _MSC_VER >= 1600
#pragma execution_character_set("utf-8")
#endif
和
QObject::tr