[SOLVED] UTF-8 and special character decoding
-
wrote on 18 Dec 2014, 10:41 last edited by
Hello,
I am getting crazy...I tried a lot of suggestions from internet without success!
I have a string, coming from internet and when I print out it, i have this:
@
qDebug()<< "received UTF-8 text: " << QString::fromUtf8(text);
@Output of above instruction is:
received UTF-8 text: Test \u003c \u003ethis escape characters are html tags ( < > )
all my file are UTF-8 (set from within QtCreator) this problem is in a .cpp file, even though qlm TextEdit is not able to manage it and show correct string!
Someone knows how to resolve this problem?
-
What is text variable in the snippet? Is it a QByteArray, char* or another QString?
-
wrote on 18 Dec 2014, 12:10 last edited by
Ah sorry...QString(char *)
I know that the above constructor can be a problem dealing with utf, but unfortunately I didn't find a solution. -
I would try with QString::fromUtf16() and QString::fromRawData(). Maybe one of them would work.
-
wrote on 18 Dec 2014, 12:21 last edited by
Ok thanks I will give a try
-
wrote on 18 Dec 2014, 13:58 last edited by
I am printing this in cpp file using qDebug and then I assign this text to a qml TextEdit...and it dispalys on android exactly that string with escape characters...unbelievable!
-
wrote on 19 Dec 2014, 13:34 last edited by
I found a solution and I write it down just to help others in case:
@
QTextCodec *codec = QTextCodec::codecForName("ISO 8859-1");QString asciiString = codec->fromUnicode(text);
@ -
Great, thank you for sharing!
1/8