Qt_win7 compiled programs run Chinese garbled characters in XP

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.