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

Thiago Macieira thiago.macieira at intel.com
Tue Aug 13 19:50:49 CEST 2013


On quarta-feira, 14 de agosto de 2013 00:35:47, Richard Turner wrote:
> 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.

That was expected. Look at what your URL was:

http%3A%2F%2F192.168.1.1%3A80%2Fservlet%2Fcom.mcdonalds.report.view.excel.ExcelReportServlet%3Ffile%3D4162%26columns%3D0%26srcType%3DdefineBean%26width%3D0%26height%3D0%26reportParamsId%3D101767%26cachedId%3D4163%26t_i_m_e%3D1376389959473&pageStyle=0

Try pasting that in a browser and see what happens.

The behaviour differs because QUrl::fromEncoded tries to interpret that as a 
URL. It has no scheme, so the entire thing is the path of the URL. Since it 
has no scheme, QNetworkAccessManager is correct in saying that "Protocol '' is 
unknown".

QUrl::fromPercentEncoding does no interpretation. It simply decodes the 
percents. After that, you call the QUrl constructor on a different URL. Let me 
repeat: on a *different* URL.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130813/a12345ce/attachment.sig>


More information about the Interest mailing list