Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Open a file with the default application in Qt
QtWS25 Last Chance

[SOLVED] Open a file with the default application in Qt

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 31.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    fs_tigre
    wrote on 1 Aug 2012, 16:31 last edited by
    #1

    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

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DerManu
      wrote on 1 Aug 2012, 17:01 last edited by
      #2

      Yep:
      @QDesktopServices::openUrl(QUrl("file:///home/fstigre/fileName.pdf"));@

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fs_tigre
        wrote on 1 Aug 2012, 18:14 last edited by
        #3

        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

        1 Reply Last reply
        0
        • F Offline
          F Offline
          fs_tigre
          wrote on 1 Aug 2012, 19:16 last edited by
          #4

          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.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DerManu
            wrote on 1 Aug 2012, 19:45 last edited by
            #5

            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?

            1 Reply Last reply
            1
            • F Offline
              F Offline
              fs_tigre
              wrote on 1 Aug 2012, 19:50 last edited by
              #6

              Make sense, sorry about my silly questions.

              Thanks a lot for the clarification.

              1 Reply Last reply
              0
              • H Offline
                H Offline
                h00bs
                wrote on 18 Jul 2018, 10:16 last edited by
                #7

                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

                Developer at Felgo - https://felgo.com/qt

                Develop mobile Apps for iOS & Android with Qt
                Develop Games with Qt

                Felgo is an official Qt Technology Partner

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved