Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QDesktopServices::openUrl() drops query string from URL...
MauriceCat last edited by
I'm using the following code to try and load a local URL:
int main(int argc, char *argv)
QApplication app(argc, argv);
QString qsHelpDoc = QCoreApplication::applicationDirPath() + "/HTML/index.html"; QUrl qurl = QUrl( QUrl::fromLocalFile( qsHelpDoc)); qurl.setQuery( "second_topic.htm"); QMessageBox::information( NULL, "URL to Open:", qurl.toString()); bool bIsValid = qurl.isValid(); QMessageBox::information( NULL, "", bIsValid? "URL is Valid" : "URL is not valid"); QDesktopServices::openUrl( QUrl( qurl));
The URL being loaded is a help file with several help topics, and I'm trying to open a specific topic to do context-sensitive help.
The full URL as constructed by the code is:
And I can type this URL into the address bar in Firefox and go to the correct help topic, so the URL looks good. However, QDesktopServices::openUrl() appears to strip out the query string and only passes this to the browser:
The end result is that the incorrect help topic is displayed. This same result occurs in Windows Qt 5.1.1 and OS X Qt 5.2.1.
Anybody see what I'm doing wrong?
Welcome to forum. This seems to be perfect query. I tried on 520 and it works the way you specified. Can you check with some other url or just open index.html first ? Does this work ?
NetZwerg last edited by
Why are you prepending your qurl variable of type QUrl() with a QUrl constructor in call to openUrl()? Probably won't solve the problem, but its still not required.
MauriceCat last edited by
Thanks for the suggestions.
I first tried opening:
followed by the full URL of:
But, the query string still gets dropped from the full URL.
What's interesting is that if I open this remote URL:
QDesktopServices::openUrl( QUrl( "https://www.google.com/?gws_rd=ssl#q=Qt"));
the query string goes through to the browser and Google does a search on "Qt".
Now, if I save the Google home page to the local HTML file C:\test\Google.htm and then try to open the following URL with openURL():
then the browser does not get the query string and only sees:
So, it looks like query strings go through to the browser for remote URLs, but not for local file URLs.
Good point. I removed the QUrl() prepend and changed:
QUrl qurl = QUrl( QUrl::fromLocalFile( qsHelpDoc));
to this simpler version:
QUrl qurl = QUrl::fromLocalFile( qsHelpDoc);
But, as you suspected, this did not make a difference.
Thanks for your time, guys.