Qt solves the problem of Chinese gibberish
qt generally set in the designer interface Chinese title what can be displayed normally.
but in QString, for example, when QPainter is painting Text, if the char* passed in contains Chinese, it will usually show a garbled code. At this time, two places need to be set:
- in main. CPP set QTextCodecQString using static method fromLocal8Bit(char*)
for the first place, set in main. CPP as follows:
#include "MainWindow.h"
#include <QApplication>
#include <QTextCodec>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTextCodec* codec = QTextCodec::codecForName("GB2312");
QTextCodec::setCodecForLocale(codec);
MainWindow w;
w.show();
return a.exec();
}
For the second place, use the following method in a char* containing Chinese characters:
QString::fromLocal8Bit(char*)
Where you want to pass in a QString, if Chinese is included, you need to do the above two Settings.
Read More:
- Solving Chinese garbled code in Java compressed file
- Solve the problem of Chinese garbled code of actibpm plug-in in idea
- Solution of Chinese display garbled code in Git Bash
- The problem of Chinese garbled data in MySQL
- Solution to the problem of Chinese garbled in gradle console in idea
- Resttemplate Chinese garbled problem – available
- After Oracle 11g is installed, SQL_ Plus.exe The problem of Chinese garbled in command window
- Configuring OpenGL in Chinese version of VS2010 and problem solving
- Solution of Chinese garbled code when using QT
- Python – [encoding] in Python os.system Solution to Chinese garbled code when calling CMD command
- Solve the problem of using logback console to print log Chinese characters in IDEA as garbled characters
- Solution to garbled code problem after importing project in eclipse
- Chinese garbled fonts in win10 English system
- Chinese garbled code when vscode calls CMD to run C / C + +
- The use of Chinese characters in Qt and the solution to the “error C2001: newline in constant” problem
- Solve the problem of garbled code when Python connects to ADB
- Anaconda Matplotlib drawing Chinese garbled solution
- How to solve the problem of string to CString garbled code?
- Java was started but returned exit code = 13 problem solving
- The garbled problem of hot deployment in nginx