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