SPlatten SPlatten - 3 months ago 22
C++ Question

Qt translate escape sequence

I have:

ºC


I want to translate this for display into ºC

I'm using Qt 5.6, is there a built in function I can call to translate this sequence?

Qt has functions to translate the symbol to an escape sequence:

QString QString::toHtmlEscaped()


But what I need is the corresponding function to translate back to the original.

Answer

You can use QTextDocument or QTextDocumentFragment to decode html entities:

QString html_string = "ºC";
QString plain_string = QTextDocumentFragment::fromHtml(b).toPlainText();