在主函数添加:
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
例如:
#include "hello.h"
#include <QApplication>
#include <QTextCodec>
int main(int argc,char*argv[])
{
QApplication app(argc,argv);
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
MyWidget w;
w.show();
return app.exec();
}