Maybe you are using this method to implement culture, but it is not rigorous enough.
Laguage» C ++
Title» Methods with the highest frequency
- # Include <qtextcodec>
- Int main (INT argc, char * argv [])
- {
- Qapplication app (argc, argv );
- // Set Chinese to start
- Qtextcodec: setcodecfortr (qtextcodec: codecforname ("gb18030 "));
- // Set Chinese end
- Return app.exe C ();
- }
Many places will tell you that QT supports Chinese characters, including the tutorials I read. He even told me that this code must be added to support Chinese characters, but I want to tell you, there is a problem with this method, and this problem is not small! When I port two machines that are also Windows XP, Chinese garbled characters occur, and TR () is used for all Chinese characters. So don't be superstitious about those tutorials. Practice is the truth!
You can try this method
Laguage» C ++
Title»
- # Include <qtextcodec>
- Int main (INT argc, char * argv [])
- {
- Qapplication app (argc, argv );
- // Set Chinese to start
- Qtextcodec * codec = qtextcodec: codecforname ("gb2312 ");
- Qtextcodec: setcodecforlocale (codec );
- Qtextcodec: setcodecforcstrings (codec );
- Qtextcodec: setcodecfortr (codec );
- // Set Chinese end
- Return app.exe C ();
- }
Although this method seems more rigorous, you can try it. However, there will still be problems in this writing, at least it will not solve my problem. This is also a high frequency method I have seen on the Internet, but I want to say: in fact, this method is not a cure, because it is only to broaden the scope of Chinese support, generally, we recommend that you write Chinese Characters in tr.
Recommend a safer method
Laguage» C ++
Title» My recommended methods
- Int main (INT argc, char * argv [])
- {
- Qapplication A (argc, argv );
- Qtextcodec * codec = qtextcodec: codecforname ("system"); // obtain the system code
- Qtextcodec: setcodecforlocale (codec );
- Qtextcodec: setcodecforcstrings (codec );
- Qtextcodec: setcodecfortr (codec );
- Return a.exe C ();
- }
I have obtained the system font code and solved my problem. I personally think this solution should be a good solution.
It may also be garbled characters caused by improper font selection.
If you cannot solve the Garbled text problem all the time, you can try to set the font, but whether the font causes Garbled text is very simple. If there are blocks, the font is improperly set. Otherwise, encoding settings are preferred.
From http://www.ctogo.net/313.html