Solutions to Chinese garbled characters in QT

Source: Internet
Author: User

At the beginning of the design, QT considered multi-language support. therefore, it is easier to support Chinese characters. it is easy to compile multi-language programs. chinese support for qtopia/QT. there are mainly the following situations:

1. Add Chinese support to your QT program.

2. display Chinese characters on the qtopia Desktop

The idea of multi-language support for Qt applications is that it is very similar to Windows. That is, non-English strings are not compiled in the program. Instead, it is saved in a dictionary file. Use the dictionary index in the program. In this way, if the program is not modified, it can be displayed in different languages as long as it is replaced with different dictionary files.
In a Windows program, this string is a resource file (*. Res), which is finally linked to an executable file. Use the resource ID of the integer type in the program to extract the string from the resource file through the API function loadstring.
Similar procedures are also used in QT. The string is stored in the translation file (*. Ts). When published, it is converted to a binary. QM file. This file does not need to be linked to the executable file. The program uses an English string as the dictionary index. Use the tr () function to retrieve the corresponding string from the translation file.

Here I will summarize the first method. (My project name is mutildialog)

First, you need to manually modify the pro file. Add the TS file option, addTranslations =Mutildialog. Ts

2. Use the lupdate tool provided by QT to generate a TS file. Enter

Lupdate mutildialog. Pro

A mutildialog. Ts file is automatically generated. TS files are actually a simple file written in XML.

 

3. Use the built-in QT tool linguist to translate mutildialog. Ts words. You can also open the mutildialog. Ts file and manually modify it.

4. Use the tool provided by QT to compile mutildialog. Ts into a binary mutildialog. QM file. Enter lrelease mutildialog. Ts in the command line to generate the corresponding file.

5. Add support for the qtranslator class to the main program. And mount the corresponding QM file.

# Include <qapplication. h>
# Include <qtranslator. h>

 

Int main (INT argc, char ** argv)
{
Qapplication A (argc, argv );

.......
Qtranslator Translator (0 );
Translator. Load (qstring ("mutildialog. QM "));
A. installtranslator (& translator );

................

Return a.exe C ();
}

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.