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
}
相關文章
相關標籤/搜索