views:

348

answers:

2

I'm getting from server data using signal and slot. Here is slot part:

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

Problem is, that in text variable will be unicode escape, for example:

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

Is there any way to convert this?

A: 

Did you try:

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

http://doc.qt.nokia.com/4.6/qstring.html#fromUtf8

Assuming it's Utf8, otherwise use fromUtf16

Adam W
I think OP means he's getting Unicode escape byte sequence. ie: '\','u','0','4','3','d' 6 bytes representing a 16-bit code point.
Stephen Chu
It works only if i write something like:QString text = QString::fromUtf8("\u043d\u0435");Maybe it's because in response from server can be not only escape, for example:[{"recipient":{"favourites_count":1,"profile_text_color":"000000","url":null,"description":"\u0421\u0442\u0443\u0434\u0435\u043d\u0442 4-\u0433\u043e \u043a\u0443\u0440\u0441\u0430 \u041c\u0418\u042d\u041c
smsteel
Are you passing the entire `[{"recipient":{"favourites_count":1,"profile_text_color":"000000","url":null,"description":"\u0421\u0442\u0443\u0434\u0435\u043d\u0442 4-\u0433\u043e \u043a\u0443\u0440\u0441\u0430 \u041c\u0418\u042d\u041c` in, or just the unicode part? I think you will have to do some work to separate the sections first since its mixed formatting.
Adam W
A: 

How about this one??

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

By using the above snippet, you can replace the single slash to double slash, so that the single slash can be obtained as such. Hope it works.

liaK