1. Change main.cpp to Utf-8 encoding by clicking Main.cpp and selecting the Advanced Save option, menu file. "All source code is converted to uft-8."
2, in your main function, set the following code, the perfect solution to qt5 Chinese garbled
Msc_ver is a built-in macro for the MSVC compiler that defines the version of the compiler. Here are some compiler versions of the _msc_ver values
MS VC + + 10.0 _msc_ver = 1600 "VC2010"
MS VC + + 9.0 _msc_ver = 1500 "VC2008"
MS VC + + 8.0 _msc_ver = 1400 "VC2005"
MS VC + + 7.1 _msc_ver = 1310
MS VC + + 7.0 _msc_ver = 1300
MS VC + + 6.0 _msc_ver = 1200
MS VC + + 5.0 _msc_ver = 1100
#include "Testchinese2.h"
#include <QtWidgets/QApplication>
#include <QDebug>
The code must be: UTF-8 (BOM)
QT version higher than or equal to Qt5,vs version is higher or equals VS2010
#if _msc_ver >= 1600
#pragma execution_character_set ("Utf-8")
#endif
int main (int argc, char *argv[])
{
Qapplication A (argc, argv);
QT version less than QT5
#if qt_version < Qt_version_check (5,0,0)
VS version Less than VS2010
#if defined (_msc_ver) && (_msc_ver < 1600)
QTEXTCODEC::SETCODECFORTR (Qtextcodec::codecforname ("GBK"));
#else
QTEXTCODEC::SETCODECFORTR (Qtextcodec::codecforname ("UTF-8"));
#endif
#endif
TestChinese2 W;
W.show ();
Qdebug () << "Hello, 333";
return A.exec ();
}
C + + vs.net setting UTF8 characters