QT Learning Path "1": QT Display Chinese issues

Source: Internet
Author: User

Recently, the GUI interface of the company project uses QT, the study of QT discovery in the last two months is really a problem, there are two main problems in this problem:

"1" Chinese display;

"2" Chinese garbled;

The "1" problem occurs when the situation is: QT interface only the English alphabet, Chinese one is not displayed, and will not appear garbled; the "2" problem arises from the scenario where the QT interface would have been replaced by garbled characters.

The reason for the "1" problem is that there is no corresponding font in the QT Library, which is provided to the QT interface

The cause of the "2" problem is: the problem of Chinese encoding conversion.

byte order mark (BOM)appears at the beginning of the byte stream, when you save the UTF-8 encoded file under Windows, the BOM (0XEF,0XBB,0XBF) is inserted at the beginning, allowing the editor to identify whether the file is UTF-8 encoded. The standard UFT-8 is not with the BOM. In other words, if the Linux system, the file encoding format can ignore the BOM: Note: Do not select "Add if Encoding is UTF-8" when setting "UTF-8 BOM" under "Tool", "Options" under Qtcreator (Linux platform), if you select this item, The BOM is added when the code is written, and then the error occurs when compiling.
several encoding formatsUTF-8Unicode Transformationformat-8bit, with BOM included, but standard UTF-8 without BOM, used to unify international characters, Strong versatility, which belongs to the International Code, it uses 8 bits (that is, one byte) for English, and Chinese uses 24 for (three bytes) to encode. UTF-8 encoded text can be displayed on browsers that support the UTF8 character set in each country. If it is UTF8 code, it can also display Chinese in the foreigner's English ie, they do not need to download IE's Chinese language support package.
gbk/gb2312GBK is the national standard GB2312 on the basis of expansion after the compatibility of GB2312 standards. The text encoding of the GBK is expressed in double-byte notation, that is, both Chinese and English characters are represented by double-byte, in order to distinguish the language, the highest bit is set to 1. GBK contains all Chinese characters, is the country code, the generality is worse than the UTF8.
UnicodeUnicode stores a number of encoded characters, which can be seen as a collection of many encoding formats. The reason why garbled characters occurthere are several encoding formats for the file, so the same binary can be translated into different symbols. Then, when a file is edited in this way, but it is opened with another encoding, it is garbled, and the reason for this is that the characters in the two coded formats are stored differently. So what is garbled in QT? The encoding format for qtcreator under the Linux platform is UTF-8, which is encoded using three bytes, while the qstring in QT is encoded using Unicode. Unicode has a number of characters in encoded format. So when a string of Chinese is assigned to the variable a defined by qstring, there is a problem, what kind of encoding does this string of text store in Unicode? If it is stored in a UTF-8 way, the fonts on Qt will appear normal and garbled if stored in a different encoding. In the QT program, if you do not specify which encoding to use to store to Unicode, then the default Latin-1 encoding, so when the QT display in Chinese, it will appear garbled!
So when you paste a few lines of code in a program, it's the role of indicating which encoding is used in the program's Chinese to store in UnicodeQT (Desktop) Chinese display and garbled solution

There is no corresponding Chinese character library in Qt, so it is impossible to display Chinese, because I started to compile QT without adding the following parameters
workaround: Recompile the QT library
configuration: ./ Configure  -fontconfig
install: Make install
test: After the recompile is complete, go to the bin directory under the QT installation directory and run. Qtconfig, select font in the interface that appears, font appears wenquan*** font, indicating the installation is successful. Then the font is set and Chinese is displayed

As for the garbled, then the code on the paste can be. QT (embedded) Chinese display and garbled solutionI met the main problem is the Chinese display, just start the Development Board on the screen without a Chinese character, garbled also not. I knew it was a question of the font. Downloaded the Wenquanyi Zen Hei font and put it in the. /font folder below also not (there are a lot of fonts under this folder), and finally delete the font under this folder to only one of the remaining, the text is displayed. After a step-by-step test, the reason was finally found: No font was set for use. Because this program is written by people from previous companies, let me debug bugs, deceptive. So why does the program not determine which font to use, only one font will be displayed in Chinese, and the font will not be displayed after a variety of fonts? I didn't find the answer to the question. It may be because: multiple fonts, the program is not sure which font to use the sake of it.


References: Baidu Encyclopedia: http://baike.baidu.com/subview/126558/5073178.htm
Several common encoding methods for characters: http://blog.csdn.net/csywwx2008/article/details/17137097
QT Chinese garbled problem: http://blog.csdn.net/brave_heart_lxl/article/details/7186631
(original) QT 4.7 support Chinese (QT4.7) (Chinese) (MAKEQPF) http://www.cnblogs.com/liu_xf/archive/2011/07/05/2098144.html

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

QT Learning Path "1": QT Display Chinese issues

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.