Character encoding conversion of QT

Source: Internet
Author: User

The developed terminal needs to be connected to two peripherals, and the second generation card reads the device and the printer.

The depressing thing is that the character encoding of the two devices is inconsistent with the terminal system, which took a lot of time at first and then noticed the problem of character encoding.

The data read from the second generation is encoded in Unicode, and the print child requires that the data in the past be converted to Unicode encoding.

Looking up the help document and finding that QT has its own transformation function, that's great.

The first is the data of the second generation of evidence:

QString Text = qtextcodec::codecforname ("GB2312")->fromunicode (str);

The terminal system uses the GB2312 code, and STR is a Unicode-encoded data buffer read from the second generation card.

This gets the text, it can be displayed on the terminal normally.

About the printer, on the contrary, it is asking us to transfer the data to Unicode:

Printbuf = Qtextcodec::codecforname ("GB2312")->tounicode ((text));

As for UTF-8 or other coding conversions, look at the QT help document.

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.