如果要是在界面上显示中文,最好是全部用英文写代码,再把需要用中文的地方翻译过来,加载QM文件。要是读写文件就在就在文件操作的时候设置QtextCodec。
在Main.cpp里设置QtextCodec不是好办法。
像下面这样写能正常显示中文,但不是好办法。
QTextCodec *codec = QTextCodec::codecForName("System");
QTextCodec::setCodecForLocale(codec);
QTextCodec::setCodecForCStrings(codec);
QTextCodec::setCodecForTr(codec);