Maybe you're using this method to achieve Chinese culture, but it's not rigorous enough .
Laguage»c++
Title» The most frequently occurring method #include <QTextCodec> int main (int argc, char *argv[]) {qapplication app (argc, argv); Set Chinese start qtextcodec::setcodecfortr (qtextcodec::codecforname ("GB18030")); Set Chinese end return app.exec (); }
Many places will tell you that this can be achieved QT support Chinese, including I read the tutorial book also, he even told me to support Chinese must join this code, but I want to tell you that this approach is problematic, and this problem is not small. I was in two of the same XP system on the machine on the transplant has appeared in Chinese garbled problem, and all Chinese are used tr (). So please 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,&NBSP;ARGV) ; //set Chinese start qtextcodec *codec = qtextcodec::codecforname (" GB2312 "); qtextcodec:: Setcodecforlocale (codec); Qtextcodec::setcodecforcstrings (codec); &NBSP;&NBSP;QTEXTCODEC::SETCODECFORTR (codec); //Set Chinese end return App.exec (); }
Although this method seems to be more rigorous, you can try, but there is still a problem in writing, at least not solve my problem. This is what I see on the internet is also very high frequency, but I want to say is: In fact, this method is not a cure for the root cause, because it is only to broaden the scope of support for Chinese, and generally we are recommended to write Chinese in the TR (""). recommend a more insurance approach laguage»c++ Title» I recommend the method int main (int argc, char *argv[]) {qapplication A (argc, argv); Qtextcodec *codec = Qtextcodec::codecforname ("System"); Get system code Qtextcodec::setcodecforlocale (codec); Qtextcodec::setcodecforcstrings (codec); QTEXTCODEC::SETCODECFORTR (codec); return A.exec (); }
This gets the system font code, solves my problem, the individual also thought this method should be a good solution. may also be improper font selection caused by garbled
If you always solve the problem of garbled, you can try to set the next font, but whether it is the font caused by garbled method is very simple, if there is a block, is the font settings are inappropriate, otherwise, priority to consider the encoding settings.
Transfer from http://www.ctogo.net/313.html