QT5中文乱码

解决QT5乱码问题

问题重现

解决方法1
#include <qtextcodec.h>

QTextCodec* codec = QTextCodec::codecForName("GBK");
this -> setWindowTitle(codec -> toUnicode("这是标题"));
解决方法2
this -> setWindowTitle(QString::fromLocal8Bit("这是标题"));
解决方法3(适用于MSVC 2017 64bit)
this -> setWindowTitle(QStringLiteral("这是标题"));
补充
// 在.pro文件添加
msvc {
    QMAKE_CFLAGS += /utf-8
    QMAKE_CXXFLAGS += /utf-8
}
相关文章
相关标签/搜索