[SOLVED] Open a file with the default application in Qt
-
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
-
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
-
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?
-
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