the QString(const char *) constructor in Qt 5 expects UTF-8 and UTF-8 only. In Qt 4, it uses the QTextCodec::codecForCStrings() if one was set, or falls back to Latin-1 — so if you pass data in any other encoding, including UTF-8, it may horribly break;

What is Unicode in Qt?

Qt uses Unicode to store, draw and manipulate strings. In many situations you may wish to deal with data that uses a different encoding. For example, most Japanese documents are still stored in Shift-JIS or ISO 2022-JP, while Russian users often have their documents in KOI8-R or Windows-1251.

What is the UTF-8 encoding for a char * string?

In all of the QString functions that take const char * parameters, the const char * is interpreted as a classic C-style ‘\\0’ -terminated string encoded in UTF-8. You may use QStringLiteral to wrap string literals as an optimization, but this is not required.

What is the QString constructor in Qt 5?

the QString (const char *) constructor in Qt 5 expects UTF-8 and UTF-8 only. In Qt 4, it uses the QTextCodec::codecForCStrings () if one was set, or falls back to Latin-1 — so if you pass data in any other encoding, including UTF-8, it may horribly break; the static QString::fromLatin1 () method builds a string from Latin-1 encoded data;

How do you convert Char to Unicode in QString?

QString converts the const char * data into Unicode using the fromUtf8() function. In all of the QString functions that take const char * parameters, the const char * is interpreted as a classic C-style ‘0’-terminated string encoded in UTF-8.

How do I get the qbytearray version of a string?

QString provides the following three functions that return a const char * version of the string as QByteArray: toUtf8(), toLatin1(), and toLocal8Bit(). toLatin1() returns a Latin-1 (ISO 8859-1) encoded 8-bit string. toUtf8() returns a UTF-8 encoded 8-bit string.