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. How to add PDF files in QT application.
Forum Updated to NodeBB v4.3 + New Features

How to add PDF files in QT application.

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 5 Posters 2.1k Views 1 Watching
  • 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.
  • P Offline
    P Offline
    Pranit Patil
    wrote on 6 Sept 2018, 04:48 last edited by
    #1

    How to add PDF files in QT application.

    I am developing the Qt application. I want to add some PDF files related to application manual into Help section. how can add this PDF files in Qt application.

    ex. in Qt creator only have Help section there we get some pdf files related to qt api.

    Thank You.

    @Embedded Software Developer
    God has given you one face, and you make yourself another.

    1 Reply Last reply
    0
    • P Offline
      P Offline
      Pranit Patil
      wrote on 6 Sept 2018, 06:01 last edited by
      #2

      Please help me here.
      any hint ?

      @Embedded Software Developer
      God has given you one face, and you make yourself another.

      R 1 Reply Last reply 6 Sept 2018, 06:45
      0
      • P Pranit Patil
        6 Sept 2018, 06:01

        Please help me here.
        any hint ?

        R Offline
        R Offline
        raven-worx
        Moderators
        wrote on 6 Sept 2018, 06:45 last edited by
        #3

        @Pranit-Patil
        patience.... no need to bump the thread after 1h

        Take a look at the QtHelp module for example.

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        4
        • V Offline
          V Offline
          VRonin
          wrote on 6 Sept 2018, 07:54 last edited by VRonin 9 Jun 2018, 10:26
          #4

          Save the pdf file inside your resources (.qrc files) then you can open them via:

          QString destinationTemp = QDir::fromNativeSeparators(QDir::tempPath());
          if(!destinationTemp.endsWith('/'))
          destinationTemp.append('/');
          QString fileName = "manual";
          if(QFile::exists(destinationTemp + fileName + ".pdf"){
          fileName  = "manual %1";
          unsigned int i=0
          for(;QFile::exists(destinationTemp + fileName.arg(i) + ".pdf");++i){}
          fileName  = fileName.arg(i);
          }
          QFile::copy(":/docs/manual.pdf",destinationTemp + fileName   + ".pdf");
          QDesktopServices::openUrl(QUrl::fromLocalFile(destinationTemp + fileName   + ".pdf"));
          

          P.S.
          this is not the first time you are warned not to bump the topic too fast, let's make it the last, shall we?!

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          J 1 Reply Last reply 6 Sept 2018, 08:11
          6
          • V VRonin
            6 Sept 2018, 07:54

            Save the pdf file inside your resources (.qrc files) then you can open them via:

            QString destinationTemp = QDir::fromNativeSeparators(QDir::tempPath());
            if(!destinationTemp.endsWith('/'))
            destinationTemp.append('/');
            QString fileName = "manual";
            if(QFile::exists(destinationTemp + fileName + ".pdf"){
            fileName  = "manual %1";
            unsigned int i=0
            for(;QFile::exists(destinationTemp + fileName.arg(i) + ".pdf");++i){}
            fileName  = fileName.arg(i);
            }
            QFile::copy(":/docs/manual.pdf",destinationTemp + fileName   + ".pdf");
            QDesktopServices::openUrl(QUrl::fromLocalFile(destinationTemp + fileName   + ".pdf"));
            

            P.S.
            this is not the first time you are warned not to bump the topic too fast, let's make it the last, shall we?!

            J Offline
            J Offline
            JonB
            wrote on 6 Sept 2018, 08:11 last edited by JonB 9 Jun 2018, 08:12
            #5
            This post is deleted!
            1 Reply Last reply
            0
            • P Offline
              P Offline
              Pranit Patil
              wrote on 16 Oct 2018, 13:39 last edited by
              #6

              Thanks to all.
              I got simple solution to open PDF file on Windows System through QT.
              Save your pdf file in Build directory then you can open them via:

              QDir dir;
              QString path = dir.absolutePath();
              path.append("/Manual.pdf");
              QDesktopServices::openUrl(QUrl::fromLocalFile(path));

              its work fine for me.

              @Embedded Software Developer
              God has given you one face, and you make yourself another.

              J 1 Reply Last reply 17 Oct 2018, 04:38
              0
              • P Pranit Patil
                16 Oct 2018, 13:39

                Thanks to all.
                I got simple solution to open PDF file on Windows System through QT.
                Save your pdf file in Build directory then you can open them via:

                QDir dir;
                QString path = dir.absolutePath();
                path.append("/Manual.pdf");
                QDesktopServices::openUrl(QUrl::fromLocalFile(path));

                its work fine for me.

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 17 Oct 2018, 04:38 last edited by
                #7

                @Pranit-Patil You don't specify explicitly where to store the file. I guess it will be current working directory. If this directory is not writeable by the user it will not work. You should use http://doc.qt.io/qt-5/qtemporaryfile.html

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                P 1 Reply Last reply 17 Oct 2018, 05:30
                1
                • J jsulm
                  17 Oct 2018, 04:38

                  @Pranit-Patil You don't specify explicitly where to store the file. I guess it will be current working directory. If this directory is not writeable by the user it will not work. You should use http://doc.qt.io/qt-5/qtemporaryfile.html

                  P Offline
                  P Offline
                  Pranit Patil
                  wrote on 17 Oct 2018, 05:30 last edited by
                  #8

                  @jsulm i mention Save pdf file in Build Directory.

                  @Embedded Software Developer
                  God has given you one face, and you make yourself another.

                  J 1 Reply Last reply 17 Oct 2018, 05:39
                  0
                  • P Pranit Patil
                    17 Oct 2018, 05:30

                    @jsulm i mention Save pdf file in Build Directory.

                    J Offline
                    J Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on 17 Oct 2018, 05:39 last edited by
                    #9

                    @Pranit-Patil Sure, but what will happen when you deploy/install your app?

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    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