Chinese garbled problem, record. Maybe you're using this method to achieve culture, but it's really not rigorous . 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 will enable QT to support Chinese, including the tutorials I read, and he even told me to support Chinese must join this code, but I would like to tell you that this approach is problematic, and this problem is not small. I was in two XP system of the same machine on the transplant, there is a Chinese garbled problem, and all Chinese are used tr (). So please don't be superstitious in those tutorials, practice is the truth. You can try this way laguage»c++ Title»
#include <QTextCodec>
int main (int argc, char *argv[])
{
qapplication app (argc, argv);
Set Chinese start
qtextcodec *codec = Qtextcodec::codecforname ("Gb2312″");
Qtextcodec::setcodecforlocale (codec);
Qtextcodec::setcodecforcstrings (codec);
QTEXTCODEC::SETCODECFORTR (codec);
Set Chinese end return
app.exec ();
}
Although this method seems more rigorous, you can try, but there will be a problem, at least not solve my problem. This is also my online to see the frequency is also very high method, but I would like to say is: In fact, this solution is not a cure, because it is only to broaden the scope of support for Chinese, and generally we all suggest that the Chinese written in tr (""). recommend a more insurance approach laguage»c++ Title» The method I recommend
int main (int argc, char *argv[])
{
qapplication A (argc, argv);
Qtextcodec *codec = Qtextcodec::codecforname ("System"); Obtain the system encoding
Qtextcodec::setcodecforlocale (codec);
Qtextcodec::setcodecforcstrings (codec);
QTEXTCODEC::SETCODECFORTR (codec);
return a.exec ();
}
This gets the system font code, solves my problem, personally also thinks this method should be a good solution. may be improper font selection caused by the garbled
If you always can not solve the garbled problem, you may try to set the font, but in fact, is the font caused by the garbled method is very simple, if the occurrence of a box, that is, improper font settings, otherwise, give priority to coding settings.
Split Line *********************** reprint speech ************************ *************************************
Ps:
qtextcodec* codec = qtextcodec::codecforname ("UTF8"); If changed to: GB2312, also will appear garbled, as for what reason look forward to everyone answer
Qtextcodec::setcodecforlocale (codec);
Qtextcodec::setcodecforcstrings (codec);
QTEXTCODEC::SETCODECFORTR (codec);
Qdebug () << "This is Chinese";
return A.exec ();
Turn from: http://www.ctogo.net/313.html