QT Chinese garbled problem solving method

Source: Internet
Author: User
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































































Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.