QDesktopServices::openUrl() drops query string from URL...
-
Greetings,
I'm using the following code to try and load a local URL:
@
#include <QApplication>
#include <QUrl>
#include <QDesktopServices>
#include <QMessageBox>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:
file:///c:/test/HTML/index.html?second_topic.htm
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:
file:///c:/test/HTML/index.html
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?
Thanks,
Kevin -
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 ?
-
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.
-
Deehandra,
Thanks for the suggestions.
I first tried opening:
file:///c:/test/HTML/index.html
followed by the full URL of:
file:///c:/test/HTML/index.html?second_topic.htm.
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():
file:///C:/test/Google.htm?gws_rd=ssl#q
then the browser does not get the query string and only sees:
file:///C:/test/Google.htm
So, it looks like query strings go through to the browser for remote URLs, but not for local file URLs.
NetZwerg,
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.
Kevin