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

Mandeep Sandhu mandeepsandhu.chd at gmail.com
Wed Aug 14 07:24:53 CEST 2013

Hi Thiago,

On Tue, Aug 13, 2013 at 11:20 PM, Thiago Macieira <thiago.macieira at intel.com
> wrote:

> 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

The docs of QUrl::fromEncoded() (Qt 4.8) state : "input is assumed to be in
encoded form, containing only ASCII characters".

Why does it assumes the input to be only the path? Is the caller expected
to explicitly 'set' the scheme on a url returned by it? If so, the docs
statement looks incomplete.

However, in the above url if we decode all percent-encoded chars upto the
port, then the scheme starts getting detected. This behaviour seems
confusing at best.

Also, if we are getting a percent encoded 'string' from external source,
whats the correct way of making it into a QUrl?

QUrl url;

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130814/bb73c8d7/attachment.html>

More information about the Interest mailing list