[SOLVED] Open a file with the default application in Qt
-
wrote on 1 Aug 2012, 16:31 last edited by
Hi,
How can I open a certain file with the default application when a button is clicked?
In other words what I want is to be able to open a file when a button is click but open it with the default application, for instance if I want to open fileName.pdf I want this to be opened with Adobe Reader.
Is there a way to do that in Qt?
Thanks
-
wrote on 1 Aug 2012, 17:01 last edited by
Yep:
@QDesktopServices::openUrl(QUrl("file:///home/fstigre/fileName.pdf"));@ -
wrote on 1 Aug 2012, 18:14 last edited by
Thanks a lot!
That works fine for .pdfs and .txt files but if I try an .html file it takes minutes to open it.
I was looking the documentation for QDesktopServices and it looks like it is possible to specify the name of the application but I cannot make it work. Or even better, will this make a difference if I add the app name?
How can I specify the name of the app?
I tried...
@QDesktopServices::openUrl(QUrl("file:///X:/test/docs/myFile.html"), "iexplorer.exe" );@
But it doesn't work.Thanks
-
wrote on 1 Aug 2012, 19:16 last edited by
Just ignore my previous post, I think is just my system.
But if you think it could benefit by specifying the application's name please let me know.
Thanks a lot for your time.
-
wrote on 1 Aug 2012, 19:45 last edited by
In fact you don't want to specify the application's name, you want QDesktopServices and the OS figure out which application the user has configured to open such documents. In your "iexplorer.exe" case: What if it's a sensible persion that uses opera, firefox or chrome? Or if it's a really sensible person and using linux where there's no such thing as an .exe let alone an iexplore.exe?
-
wrote on 1 Aug 2012, 19:50 last edited by
Make sense, sorry about my silly questions.
Thanks a lot for the clarification.
-
wrote on 18 Jul 2018, 10:16 last edited by
You can also do this from QML using the V-Play FileUtils: https://v-play.net/doc/fileutils/
Here is an example code that downloads a PDF from the web and opens it using the default application on Android and iOS: https://v-play.net/web-editor/?snippet=ce64a995