Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to unescape a string in Qt?

Tags:

c++

urlencode

qt

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?

like image 708
SPlatten Avatar asked Oct 30 '18 08:10

SPlatten


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>"
like image 102
Jarod42 Avatar answered Oct 07 '22 08:10

Jarod42