QT Implementation 16 Unicode to Utf-8 and the IPA encoding problem

Source: Internet
Author: User

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. 1.16 binary Unicode converted to utf-8 Chinese display
  2. QString unicodetoutf_8 (const QString &RESSTR)
  3. {
  4. //Unicode to Utf-8 idea: A Unicode encoding occupies 2 bytes. So you just need to combine 4 16 digits.
  5. QString temp;
  6. For (int i = 0; i< resstr.length ();)
  7. {
  8. if (resstr.at (i) = = ' \ \ ')
  9. {
  10. QString str = Resstr.mid (i+2, 4);
  11. Temp.append (Str.toushort (0, 16));
  12. i + = 6;
  13. }
  14. Else
  15. {
  16. Temp.append (resstr.at (i));
  17. ++i;
  18. }
  19. }
  20. Qtextcodec *codec = Qtextcodec::codecforname ("UTF-8");
  21. QString desstr = Codec->fromunicode (temp);
  22. return Qobject::trutf8 (Desstr.tolatin1 (). data ());
  23. }
  24. 2. How to display the phonetic transcription of the 16 Unicode encoding returned in the network??
  25. QString Getthedecodesymbol (const QString &RESSTR)
  26. {
  27. //How to display the phonetic transcription of 16 Unicode encoding in the window?
  28. //For example: \u00a0[\u026an\u02c8ta\u026at (\u0259) lm\u0259nt]
  29. //decoding ideas are as follows: Convert 16 Unicode encoding into 10 Unicode encoding first
  30. the//conversion method is the following code
  31. //Then how to display it?
  32. //Set fonts with Qlabel
  33. //TR ("<span style= ' font-family:\" MS mincho\ "; ' >%1</span> "). Arg (data);
  34. QString Desstr;
  35. For (int i = 0; i< resstr.length ();)
  36. {
  37. if (resstr.at (i) = = ' \ \ ')
  38. {
  39. QString str = Resstr.mid (i+2, 4);
  40. Desstr.append (tr ("&#%1;").  Arg (str.toint (0, 16)));
  41. i + = 6;
  42. }
  43. Else
  44. {
  45. Desstr.append (resstr.at (i));
  46. ++i;
  47. }
  48. }
  49. return desstr;
  50. }

http://blog.csdn.net/wu5151/article/details/47107051

QT Implementation 16 Unicode to Utf-8 and the IPA encoding problem

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.