network resources need to be decoded due to project needs. You are experiencing coding problems. The basic coding principle is studied. So with the following two common codes
[CPP]View Plaincopy
- 1.16 binary Unicode converted to utf-8 Chinese display
- QString unicodetoutf_8 (const QString &RESSTR)
- {
- //Unicode to Utf-8 idea: A Unicode encoding occupies 2 bytes. So you just need to combine 4 16 digits.
- QString temp;
- For (int i = 0; i< resstr.length ();)
- {
- if (resstr.at (i) = = ' \ \ ')
- {
- QString str = Resstr.mid (i+2, 4);
- Temp.append (Str.toushort (0, 16));
- i + = 6;
- }
- Else
- {
- Temp.append (resstr.at (i));
- ++i;
- }
- }
- Qtextcodec *codec = Qtextcodec::codecforname ("UTF-8");
- QString desstr = Codec->fromunicode (temp);
- return Qobject::trutf8 (Desstr.tolatin1 (). data ());
- }
- 2. How to display the phonetic transcription of the 16 Unicode encoding returned in the network??
- QString Getthedecodesymbol (const QString &RESSTR)
- {
- //How to display the phonetic transcription of 16 Unicode encoding in the window?
- //For example: \u00a0[\u026an\u02c8ta\u026at (\u0259) lm\u0259nt]
- //decoding ideas are as follows: Convert 16 Unicode encoding into 10 Unicode encoding first
- the//conversion method is the following code
- //Then how to display it?
- //Set fonts with Qlabel
- //TR ("<span style= ' font-family:\" MS mincho\ "; ' >%1</span> "). Arg (data);
- QString Desstr;
- For (int i = 0; i< resstr.length ();)
- {
- if (resstr.at (i) = = ' \ \ ')
- {
- QString str = Resstr.mid (i+2, 4);
- Desstr.append (tr ("&#%1;"). Arg (str.toint (0, 16)));
- i + = 6;
- }
- Else
- {
- Desstr.append (resstr.at (i));
- ++i;
- }
- }
- return desstr;
- }
http://blog.csdn.net/wu5151/article/details/47107051
QT Implementation 16 Unicode to Utf-8 and the IPA encoding problem