Add the following code to main. cpp:
# Include <qtextcodec>
Int main (INT argc, char ** argv)
{
Qtextcodec * codec = qtextcodec: codecforname ("gb2312 ");
Qtextcodec: setcodecforlocale (codec );
Qtextcodec: setcodecforcstrings (codec );
Qtextcodec: setcodecfortr (codec );
}
In this way, you can use Chinese in other places of the program, TR ("Chinese") or directly use "Chinese;
Solve Chinese garbled characters in ini files
Qsettings settings ("XXXX. ini", qsettings: iniformat );
Settings. setinicodec (qtextcodec: codecforname ("gb2312"); // Add settings here to read and write the Chinese characters in the INI file.
Settings. begingroup ("company ");
Solve Chinese garbled characters for reading Chinese files
Qfile file ("xxxx.txt ");
Qtextstream stream (file, qiodevice: readonly );
Stream. setcodec (qtextcodec: codecforname ("gb2312 "));
Stream. readall ();
Article Source: DIY tribe (http://www.diybl.com/course/3_program/c++/cppjs/20090403/163794.html)