Home > Mobile >  Qt Chinese display garbled
Qt Chinese display garbled

Time:11-05


QT small white, want to output a string variable in interface controls (including Chinese), call QTool: : showMsg (" database connection failure ");

According to the code, including showMsg method for

Void QTool: : showMsg (QString text)
{
QString STR.
STR=QString (" % 1 "). Arg (text);
The UI - & gt; The label - & gt; SetText (STR);

}

CodePudding user response:

Added, I use the Qt5, also added QTextCodec: in the main function: setCodecForLocale (QTextCodec: : codecForName (' GBK ')); But still show the code

CodePudding user response:

reference 1st floor jiejietongxue response:
add that I use the Qt5, also added QTextCodec: in the main function: setCodecForLocale (QTextCodec: : codecForName (' GBK ')); But still show the code


This is the old way of doing, don't need this lane,
According to the code coding garbled mostly do not see your file

CodePudding user response:

//in front of the header file with a few lines of code below
# ifdef WIN32
# pragma execution_character_set (" utf-8 ")
# endif

Many online practices are very old, the above should be feasible, you try

CodePudding user response:

MSVC Qt, in front of the Chinese string u8, u8 "Chinese characters"
Mingw Qt, QStringLiteral (" Chinese characters "), before compiling the CPP with notepad file save as utf-8 format

CodePudding user response:

To use the correct encoding, want to see what exactly is a text encoding,

CodePudding user response:

ShowMsg (QString: : fromLocal8Bit (" I am a Chinese "));
Have a try?

For portability, you still keep the code files into utf-8 with BOM,
Then under the MSVC fromLocal8Bit (" Chinese "),,,, (haven't tried mingw) but qDebug () & lt; Under Linux fromUtf8 (" Chinese ")

Their definition a my_tr macros or function to deal with this situation
-- -- -- -- -- -- -- -- -- -- -- Qt5.5.1 _msvc2010 environment, Qt Creator 3.5.1 track of validation -- -- -- -- -- --

In the front of the 4th floor said with the low if the compiler version, u8 is not support,
If you vs2017 render, certainly can

CodePudding user response:

With wide character directly, Qstring: : fromWstdString (L (" text ")),
  •  Tags:  
  • Qt
  • Related