VS2015 + QT5.7 中文的坑

时间:2023-12-13 14:28:56

试验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();
}

结果如下:
VS2015 + QT5.7 中文的坑

试验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();
}

结果如下:

VS2015 + QT5.7 中文的坑

结论:

在VS中, 使用

#if _MSC_VER >= 1600
#pragma execution_character_set("utf-8")
#endif

QObject::tr