[Interest] Difference between QUrl::fromEncoded and QUrl::fromPercentEncoding ?

Richard Turner turner at yiran.org
Tue Aug 13 18:35:47 CEST 2013

On 2013/8/14 0:00, Thiago Macieira wrote:
> On terça-feira, 13 de agosto de 2013 18:44:41, Richard Turner wrote:
>>       QUrl  downloadUrl1  =  QUrl::fromEncoded(str.toUtf8());
>>       QUrl  downloadUrl2  =  QUrl::fromPercentEncoding(str.toUtf8());
> Please note QUrl::fromEncoded returns a QUrl. QUrl::fromPercentEncoding
> returns a QString. That's the difference.
> Your code above also calls the QUrl constructor taking a QString, which is a
> big no-no in Qt 4 code, but entirely acceptable in Qt 5.
> On the other hand, if you have any percent sequences not making UTF-8,
> QUrl::fromPercentEncoding will mangle them.
OK. Now the problem is, when I use downloadUrl1(result from fromEncoded) 
to make a QNetworkRequest (HTTP GET), I always detect an error: Protocol 
"" is unknown.
When I switch to use downloadUrl2, all is good.

The code is like:
         QNetworkRequest req(downloadUrl1);
         QNetworkReply *reply = networkManager->get(req);
         connect(reply, SIGNAL(finished()),
                 this, SLOT(dataPageFetchFinished()));
Then, I always detect "Protocol "" is unknown" error in the 
dataPageFetchFinished() slot function.

Any idea on why this is happening?

More information about the Interest mailing list