Qt and unicode output string

I get from server data using signal and slot. Here is the part of the slot:

QString text(this->reply->readAll()); 

The problem is that the text variable will execute unicode, for example:

 \u043d\u0435 \u043f\u0430\u0440\u044c\u0441\u044f ;-) 

Is there any way to convert this?

+4
source share
3 answers

Have you tried:

 QString text = QString::fromUtf8(this->reply->readAll()); 

http://doc.qt.io/qt-5/qstring.html#fromUtf8

Assuming this is Utf8, use fromUtf16

+2
source

I think this is what you need:

(Find the occurrences of \ uCCCC using a regular expression and replace them with QChar by the Unicode number of the database in base 16)

 QRegExp rx("(\\\\u[0-9a-fA-F]{4})"); int pos = 0; while ((pos = rx.indexIn(str, pos)) != -1) { str.replace(pos++, 6, QChar(rx.cap(1).right(4).toUShort(0, 16))); } 
+7
source

How about this?

 QString text = reply->readAll().replace("\","\\"); 

Using the snippet above, you can replace one slash with a double slash so that you can get a single slash. Hope this works.

-1
source

Source: https://habr.com/ru/post/1311652/


All Articles