I tried to construct QUrl
piece by piece:
QUrl url{"https://host.org/path"};
url.setScheme("http");
url.setPort(81);
url.setUserName("user");
url.setPassword("password");
url.setHost("server.com");
QUrlQuery urlQuery;
urlQuery.setQueryItems({{"key1", "value1"}, {"key2", "value2"}, {"key3", "value3"}});
url.setQuery(urlQuery);
url.setFragment("fragment");
//url.setPath("dir/file.htm");
qDebug() << url;
Output (password is accidentally missed on the way):
QUrl("http://user@server.com:81/path?key1=value1&key2=value2&key3=value3#fragment")
First of all, if QUrl
is default-constructed, then using setters I can't add anything into it at all.
In above code if I uncomment last but one line, then output became QUrl("")
. That is QUrl::setPath
clean up the whole internal representation of QUrl
instance.
Are both mentioned behaviours normal? Or are they the bugs?
I use Qt 5.7.1.
It seems, that simple string concatenation is much less bug prone.