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 file with it default program
QtWS25 Last Chance

[SOLVED]Open file with it default program

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 5.4k 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.
  • freddy311082F Offline
    freddy311082F Offline
    freddy311082
    wrote on last edited by
    #1

    Hi guys...

    I need to open a file with it default program defined in the OS.

    I'm doing this to open a pdf:
    @qDebug() << QDesktopServices::openUrl(QUrl("file:///home/freddy/unordered.pdf", QUrl::TolerantMode));@
    and my program crash it . I test with this code too:
    @qDebug() << QDesktopServices::openUrl(QUrl("/home/freddy/unordered.pdf", QUrl::TolerantMode));@
    and
    @qDebug() << QDesktopServices::openUrl(QUrl("file:///home/freddy/unordered.pdf"));@
    and the result is the same:
    @The program has unexpectedly finished.@
    I'm using Qt5.2.1 in Archlinux, but my app will run over Mac and Windows too,

    any advice please ?? thanks !!!

    best regards

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Can you try building your url using "fromLocalFile":http://qt-project.org/doc/qt-5/qurl.html#fromLocalFile ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • freddy311082F Offline
        freddy311082F Offline
        freddy311082
        wrote on last edited by
        #3

        Hi SGaist !!! thanks for answer !!!

        I had try:
        @qDebug() << QDesktopServices::openUrl(QUrl::fromLocalFile("file:///home/freddy/unordered.pdf"));@

        but the program stil crash it !!!

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andreyc
          wrote on last edited by
          #4

          Works for me on OSX (Qt-5.3-beta) and Ubuntu (Qt-5.2.1)
          @
          qDebug() << QDesktopServices::openUrl(QUrl::fromLocalFile("/home/user/tdd.pdf"));
          qDebug() << QDesktopServices::openUrl(QUrl("file:///home/user/GUIdesign.pdf", QUrl::TolerantMode));
          @

          Do you have a core file? Could you post a backtrace log here.

          You don't need to add "file://" if you use @QUrl::fromLocalFile(...)@

          1 Reply Last reply
          0
          • freddy311082F Offline
            freddy311082F Offline
            freddy311082
            wrote on last edited by
            #5

            yes...

            my core file is only:

            @
            #include <QDesktopServices>

            int main()
            {
            qDebug() << QDesktopServices::openUrl(QUrl::fromLocalFile("file:///home/user/unordered.pdf"));
            return 0;
            }
            @

            and the backtrace log just tell me

            @Starting /home/freddy/Trabajo/bpg/andy&pedro/proyecto/build-adviser-Clang-Debug/adviser...
            QML debugging is enabled. Only use this in a safe environment.
            The program has unexpectedly finished.
            /home/freddy/Trabajo/bpg/andy&pedro/proyecto/build-adviser-Clang-Debug/adviser crashed@

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andreyc
              wrote on last edited by
              #6

              You need to initialize QApplication in order in use QDesktopServices

              Try this
              @
              #include <QApplication>
              #include <QDebug>
              #include <QUrl>
              #include <QDesktopServices>

              int main(int argc, char *argv[])
              {
              QApplication a(argc, argv);

              qDebug() << QDesktopServices::openUrl(QUrl::fromLocalFile&#40;"/home/user/tdd.pdf"&#41;);
              qDebug() << QDesktopServices::openUrl(QUrl("file:///home/user/GUIdesign.pdf", QUrl::TolerantMode));
              
              return 0;
              

              }

              @

              1 Reply Last reply
              0
              • freddy311082F Offline
                freddy311082F Offline
                freddy311082
                wrote on last edited by
                #7

                That right andreyc

                Thank you for your help guys !!!

                It's work !!!

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  Cardlo
                  wrote on last edited by
                  #8

                  @ QString str(QDir::currentPath());
                  str.append("/ManualUsuario.pdf");
                  QDesktopServices::openUrl(QUrl::fromLocalFile(str));@

                  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