如果工程设置的编码方式是 System,可以通过编码实现。
在main.cpp中增加蓝色字体代码:
#include <QtGui/QApplication>
#include <QTextCodec>
#include "helloqt.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTextCodec::setCodecForTr(QTextCodec::codecForLocale());
HelloQt w;
w.show();
return a.exec();
}
在显示中文的Widget中采用蓝色字体代码设置:
HelloQt::HelloQt(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::HelloQt)
{
ui->setupUi(this);
ui->labelText->setText(tr("中国人"));
}
运行结果如下: