Qt and unicode escape string

眉间皱痕 提交于 2019-12-04 07:29:38
Adam W

Did you try:

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

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

Assuming it's Utf8, otherwise use fromUtf16

I think this is what you needed:

(Find occurrences of \uCCCC using regex and replace them by the QChar with unicode number CCCC 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)));
}

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!