Completely solve the problem of QT5 Chinese compilation but

When developing with Qt5 on the windows platform, the source code (.cpp or qml) may contain Chinese, causing the compilation to fail. The specific error code is shown in the figure below:
Insert picture description here

Cause Analysis

The reason for the error is that under Windows, QT only uses the "UTF-8" encoding method by default, while Chinese fonts require the "UTF-8-BOM" format.

Solution

Method 1: (Easiest)
Add the above two lines of code to the constructor of the class to solve the problem that the class contains Chinese but cannot be compiled.

QTextCodec *codec = QTextCodec::codecForName("UTF-8-BOM");
QTextCodec::setCodecForLocale(codec);

Method 2:
Use notepad++ to open each source file containing Chinese, select UTF-8-BOM for "Encoding", then save and close.
Insert picture description here

Guess you like

Origin blog.csdn.net/PRML_MAN/article/details/114019757