Solving the problem of Chinese garbled code in qtring

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: