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

Richard Turner turner at yiran.org
Tue Aug 13 16:59:06 CEST 2013


On 2013/8/13 20:11, Mandeep Sandhu wrote:
> On Tue, Aug 13, 2013 at 4:14 PM, Richard Turner <turner at yiran.org 
> <mailto:turner at yiran.org>> wrote:
>
>     |Hi,
>
>     |     QString  str  =  "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";
>
>          QUrl  downloadUrl1  =  QUrl::fromEncoded(str.toUtf8());
>          QUrl  downloadUrl2  =  QUrl::fromPercentEncoding(str.toUtf8());
>
>
>          assert(downloadUrl1.toString()  ==  downloadUrl2.toString());
>          assert(downloadUrl1  ==  downloadUrl2);
>
>     Why is the second assertion fails when the first assertion still passes? What is the underlying difference between QUrl::fromEncoded and QUrl::fromPercentEncoding?
>
>
> I think you're using Qt4 since the first assert is passing (in Qt5 it 
> would've failed as the default arg to QUrl::toString() has changed).
>
> QUrl::fromEncoded assumes the string is ASCII encoded only. Is there a 
> non-ASCII char somewhere in that url?
>
> -mandeep
>
Thanks Mandeep!

I'm running Qt 4.8.4 on Windows 7. And as you can see in the above code, 
there's no non-ASCII char in that string.

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


More information about the Interest mailing list