The source file encoding will affect the compilation result.

Source: Internet
Author: User

Conclusion:

1. Source Insight 3.50.63 cannot display Chinese characters in the Source file encoded as UTF8. The Chinese Characters in an ANSI encoded file can be properly displayed. (The same problem also exists in the latest 3.50.64 version)

2. In Windows, whether the source code file is UTF8 or ANSI, the compilation result is not affected.

3. in Linux, the source code file is UTF8 in Chinese and ANSI Chinese is garbled.

Body: The process of discovering the problem)

Today, we accidentally found that Chinese strings in SI are garbled.

650) this. width = 650; "style =" border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px "title =" image "border =" 0 "alt =" image "src =" http://www.bkjia.com/uploads/allimg/131228/1Q2201H9-0.png "" 575 "height =" 61 "/>

However, if you use notepad to open the file, it is not garbled. Copying from the interface opened by notepad to SI is not garbled.

Therefore, it can be inferred that the file is saved as an encoding, so that the SI cannot be correctly displayed.

Open the file with UE, and save an ANSI file KtvMainScreen1.cpp:

650) this. width = 650; "style =" border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px "title =" image "border =" 0 "alt =" image "src =" http://www.bkjia.com/uploads/allimg/131228/1Q22045c-1.png "" 371 "height =" 271 "/>

Then open it in SI. The Chinese character is displayed normally.

Then open with BC, found: the original SI garbled file is UTF-8 format.

650) this. width = 650; "style =" border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px "title =" image "border =" 0 "alt =" image "src =" http://www.bkjia.com/uploads/allimg/131228/1Q220M10-2.png "" 1279 "height =" 224 "/>
Select ANSI on the left to display properly:

650) this. width = 650; "style =" border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px "title =" image "border =" 0 "alt =" image "src =" http://www.bkjia.com/uploads/allimg/131228/1Q2205552-3.png "" 1280 "height =" 220 "/>

Can I use another saved file to replace the original file for compilation? Will there be garbled characters in the software?

Later, I used the following code to test the Chinese display. One method of writing the Chinese display was normal.

# Include <QApplication>
# Include <QPushButton>
# Include <QString>

Int main (int argc, char * argv [])
{
QApplication app (argc, argv );

// QPushButton hello (QObject: trUtf8 ("hello, world! "); // Garbled Chinese Characters During Windows 7.
// QPushButton hello (QObject: tr ("hello, world! "); // Garbled Chinese Characters During Windows 7.
QPushButton hello (QString: fromLocal8Bit ("hello, world! "); // Chinese Characters in Win7 are displayed normally
Hello. resize (100, 30 );

Hello. show ();
Return app.exe c ();
}
This file is ANSI stored. Save it as UTF8. After compilation, Chinese characters are still displayed normally.

However, when comparing the source file in binary format, you can find that UTF8 is one byte more than each Chinese Character in ANSI.

650) this. width = 650; "style =" border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px "title =" image "border =" 0 "alt =" image "src =" http://www.bkjia.com/uploads/allimg/131228/1Q22050G-4.png "" 1284 "height =" 804 "/>

It can be seen that on Windows, the source code file is UTF8 or ANSI encoding, and there will be no garbled characters after compilation.

Then, both types of files are compiled on Linux and UTF-8 files are found to be normal in Chinese. ANSI files are garbled in Chinese.

Related Article

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.