How to unescape a string in Qt?

Viewed 1215

I have the following example:

%3ca href%3d%22http://google.com%22%3eGoogle%3c/a%3e

When unescaped I expect this to be:

<a href="http://google.com">Google</a>

I've tried:

strUnescaped = QString::fromUtf8(strEncoded.toLatin1().data());

But the result is the same as the original unaffected and unmodified. What do I need to do?

1 Answers

You might use QUrl::fromPercentEncoding to decode percent to regular character:

QString encodedStr = "%3ca href='http://google.com'%3eGoogle%3c/a%3e";
auto decodedStr = QUrl::fromPercentEncoding(encodedStr.toLatin1());
// decodedStr == "<a href='http://google.com'>Google</a>"
Related