Open an HTML file in Internet Explorer
-
Hi guys;
When the user presses a button, I would like to open an HTML file in Internet Explorer.
I tried to use these codes, but it doesn't work:void MainWindow::on_pushButton_clicked() { QDesktopServices::openUrl(QUrl(":/Images/Help.html", QUrl::TolerantMode)); }
Thanks for helping.
MSD. -
@MSDQuick said in Open an HTML file in Internet Explorer:
but it doesn't work
And what does happen then?
Anyway, is something like https://stackoverflow.com/questions/37898660/qdesktopservicesopenurl-does-not-work-neither-for-urls-nor-for-local-files-o relevant to your situation? There are several other Google hits for
QDesktopServices::openUrl
, are they relevant? -
@JNBarchan
It does any thing.
I changed the code to this:QDesktopServices::openUrl(QUrl::fromUserInput("Help.html","/Images/"));
Now it opens a web browser and puts "Help.html" in address bar and shows error opening page.
My HTML is located in my application resources directory, and I think it can not find that address.
-
Then I presume you need to specify a (more) absolute URL. Have you tried
/Help.html
or something likehttp://localhost/Help.html
? Have you tried opening the file in IE and copying the page's URL back into your source code? I don't even know whether you are servicing these web pages via an HTTP server or just via direct file access...? -
You may have better luck if you deploy the file to your application path (or a subdirectory thereof) and then open the URL:
QDesktopServices::openUrl(QUrl("file:///" + QCoreApplication::applicationDirPath() + "/help.html"));
-
@Paul-Thompson
Good idea,
Problem solved, thanks.