QUrl::setPath deletes Url
-
Hi,
following example:
@
QUrl example1("http://www.example.com");
example1.setPath("test.html");
qDebug() << "example1:" << example1;QUrl example2("http://www.example.com");
example2.setPath("/test.html");
qDebug() << "example2:" << example2;
@Output:
@
example1: QUrl( "" )
example2: QUrl( "http://www.example.com/test.html" )
@Can somebody explain to me, why url is deleted in the first example? Is there a reason why the slash is required? Sorry for my lack of knowledge.
-
Hi,
AFAIK, "test.html" is an invalid path. You can check the definition of what a path is in the documentation of setPath
-
Yes, but does not explain why the slash is required.
@
QUrl example1("http://www.example.com");
example1.setPath("pub/something");
qDebug() << "example1:" << example1;QUrl example2("http://www.example.com");
example2.setPath("/pub/something");
qDebug() << "example2:" << example2;@@
example1: QUrl( "" )
example2: QUrl( "http://www.example.com/pub/something" )
@P.S. in PySide the first slash is not necessary
-
Hmm, i've testet the code with Qt 4.8.6 and it works. Apparently, the behavior changed in Qt5.
@
QUrl example1("http://www.example.com");
example1.setPath("pub/something");
qDebug() << "example1:" << example1;QUrl example2("http://www.example.com");
example2.setPath("/pub/something");
qDebug() << "example2:" << example2;QUrl example3("http://www.example.com/");
example3.setPath("////pub/something");
qDebug() << "example3:" << example3;
@Qt4.8.6 output;
@
example1: QUrl( "http://www.example.com/pub/something" )
example2: QUrl( "http://www.example.com/pub/something" )
example3: QUrl( "http://www.example.com////pub/something" )
@Qt5.3.2 output:
@
example1: QUrl( "" )
example2: QUrl( "http://www.example.com/pub/something" )
example3: QUrl( "http://www.example.com/pub/something" )
@Bug or Feature?
-
Based on the current QUrl test, it's a feature, no slash means a relative path so your QUrl becomes invalid since you have an authority present before.
Anyway, a check for that is on it's way