Conclusion
I did some research, the conclusion so far: absurdity .
QUrl::fromPercentEncoding() is the way to go and what the OP did in the UPDATE section should have been the accepted answer to the question in the header.
I think the Qt QUrl::toDisplayString bit misleading:
" Returns the user-displayed string representation of the URL . The output can be customized by passing flags with parameters. RemovePassword is always on, since passwords should never be shown to users."
In fact, it does not pretend to be decoding, the document here is unclear regarding its behavior. But at least part of the password is correct. I found some Gitorious hints :
" Add QUrl :: toDisplayString (), which is toString () without a password. And correct the documentation toString (), which indicated that this method should be used to display to people, while this was never true."
Security Code
To recognize the decoding ability of various functions. The following code has been tested on Qt 5.2.1 (not yet tested on Qt 5.3!)
QString target(); QUrl url_path(target); qDebug() << "[Original String]:" << target; qDebug() << "--------------------------------------------------------------------"; qDebug() << "(QUrl::toEncoded) :" << url_path.toEncoded(QUrl::FullyEncoded); qDebug() << "(QUrl::url) :" << url_path.url(); qDebug() << "(QUrl::toString) :" << url_path.toString(); qDebug() << "(QUrl::toDisplayString) :" << url_path.toDisplayString(QUrl::FullyDecoded); qDebug() << "(QUrl::fromPercentEncoding):" << url_path.fromPercentEncoding(target.toUtf8());
PS QUrl::url is synonymous with QUrl::toString .
Output
[Case 1]: When the target path = "%_%" ( check coding functionality ):
[Original String]: "%_%" -------------------------------------------------------------------- (QUrl::toEncoded) : "%25_%25" (QUrl::url) : "%25_%25" (QUrl::toString) : "%25_%25" (QUrl::toDisplayString) : "%25_%25" (QUrl::fromPercentEncoding): "%_%"
[Case 2]: When the target path = "Meow !" ( check coding functionality ):
[Original String]: "Meow !" -------------------------------------------------------------------- (QUrl::toEncoded) : "Meow%20!" (QUrl::url) : "Meow !" (QUrl::toString) : "Meow !" (QUrl::toDisplayString) : "Meow%20!" // "Meow !" when using QUrl::PrettyDecoded mode (QUrl::fromPercentEncoding): "Meow !"
[Case 3]: When the target path = "Meow|!" ( check coding functionality ):
[Original String]: "Meow|!" -------------------------------------------------------------------- (QUrl::toEncoded) : "Meow%7C!" (QUrl::url) : "Meow%7C!" (QUrl::toString) : "Meow%7C!" (QUrl::toDisplayString) : "Meow|!" // "Meow%7C!" when using QUrl::PrettyDecoded mode (QUrl::fromPercentEncoding): "Meow|!"
[Case 4]: When the target path = "http://test.com/query?q=++e:xyz/en" ( none% encoded ):
[Original String]: "http://test.com/query?q=++e:xyz/en" -------------------------------------------------------------------- (QUrl::toEncoded) : "http://test.com/query?q=++e:xyz/en" (QUrl::url) : "http://test.com/query?q=++e:xyz/en" (QUrl::toString) : "http://test.com/query?q=++e:xyz/en" (QUrl::toDisplayString) : "http://test.com/query?q=++e:xyz/en" (QUrl::fromPercentEncoding): "http://test.com/query?q=++e:xyz/en"
[Case 5]: When the target path = "http://test.com/query?q=%2B%2Be%3Axyz%2Fen" ( % encoded ):
[Original String]: "http://test.com/query?q=%2B%2Be%3Axyz%2Fen" -------------------------------------------------------------------- (QUrl::toEncoded) : "http://test.com/query?q=%2B%2Be%3Axyz%2Fen" (QUrl::url) : "http://test.com/query?q=%2B%2Be%3Axyz%2Fen" (QUrl::toString) : "http://test.com/query?q=%2B%2Be%3Axyz%2Fen" (QUrl::toDisplayString) : "http://test.com/query?q=%2B%2Be%3Axyz%2Fen" (QUrl::fromPercentEncoding): "http://test.com/query?q=++e:xyz/en"
PS I also encounter the error that Ilya mentioned in the comments: Percentage of coding does not seem to work for "+" in QUrl
Summary
The result of QUrl::toDisplayString mixed. As the document says, the QUrl::FullyDecoded should be used with caution. No matter what type of URL you get, QUrl::toEncode them QUrl::toEncode and show them with QUrl::fromPercentEncoding , if necessary.
Regarding the failure of the percentage URLs in the QWebView mentioned in the OP, debugging requires more detailed information. The reason may be different functions and the other mode used.
Useful resources