An executable program is compiled in win7 and executed in xp. Even though all Chinese characters are included in tr (), Chinese characters are still garbled.
A simple search on the Internet, see similar articles (http://www.xpsp3.com/jiaocheng/506.html), a good solution to the problem encountered.
My original code:
int main(int argc, char *argv[]){ QApplication app(argc, argv); QTextCodec::setCodecForTr(QTextCodec::codecForName("GBK")); return app.exec();}
Modified code:
int main(int argc, char *argv[]){ QApplication app(argc, argv); QTextCodec::setCodecForTr(QTextCodec::codecForName("System")); return app.exec();}
The difference is:
The former specifies a common character set for tr (), but even two XP systems cannot ensure that the character set is the same;
The latter sets the tr () Character Set Based on the Current Character Set of the system, which is more reasonable and reliable;
However, put the relevant code in the Linux system, re-compile the execution, but also a lot of garbled code, because in windows, the use of gb2312 Save the code, and the default encoding format for Linux UTF-8, therefore, there is still a problem of Chinese display.
The complete solution is:
1. Use tr () to enclose all texts visible to users. The Code only contains English;
2. Use lupdate to extract strings visible to all users and generate ts files;
3. Use QT linguist to translate ts files and release them to generate the. QM file;
4. The application uses qtranslator to load the. QM file;
Of course, it is best to use the. QM file as a resource file and embed it into an executable program.
Refer:
Http://devbean.blog.51cto.com/448512/244689
<C ++. Gui. Programming. With. qt.4> Chapter 4 Internationalization