Chinese garbled characters in QT in Ubuntu

Source: Internet
Author: User
In Ubuntu, QT displays Chinese Garbled text with the following code: # include & lt; QtGui/QApplication & gt; # include & lt; QtGui/QWidget & gt; # include & lt; qtGui/QLabel & gt; # include & lt; QtCore/QTextCodec & gt; # include & lt; QtGui/QPushButton & gt; # include & lt;

Chinese garbled characters in QT in Ubuntu

Post Code first
# Include
# Include
# Include
# Include
# Include
# Include
Int main (int argc, char * argv [])
{
QApplication app (argc, argv );

QWidget * pWidget = new QWidget;
QLabel label (pWidget );
QTextCodec: setCodecForTr (QTextCodec: codecForName ("GB18030 "));
Label. setText (QObject: tr ("the same world, the same dream "));
QPushButton * btn = new QPushButton (QObject: tr ("disabled"), pWidget );
QVBoxLayout * layout = new QVBoxLayout;
Layout-> addWidget (& label );
Layout-> addWidget (btn );
PWidget-> setLayout (layout );
QObject: connect (btn, SIGNAL (clicked (), pWidget, SLOT (close ()));
PWidget-> show ();
Return app.exe c ();
}

Garbled above
Solution:
First, save the file as utf8 encoding format. If creator is used, select the last sub-menu in the edit menu.
Replace the second GB18030 with utf8

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.