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.
  • Pranit PatilP Offline
    Pranit PatilP Offline
    Pranit Patil
    wrote on 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
    • Pranit PatilP Offline
      Pranit PatilP Offline
      Pranit Patil
      wrote on last edited by
      #2

      Please help me here.
      any hint ?

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

      raven-worxR 1 Reply Last reply
      0
      • Pranit PatilP Pranit Patil

        Please help me here.
        any hint ?

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on 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
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by VRonin
          #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

          JonBJ 1 Reply Last reply
          6
          • VRoninV VRonin

            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?!

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5
            This post is deleted!
            1 Reply Last reply
            0
            • Pranit PatilP Offline
              Pranit PatilP Offline
              Pranit Patil
              wrote on 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.

              jsulmJ 1 Reply Last reply
              0
              • Pranit PatilP Pranit Patil

                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.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on 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

                Pranit PatilP 1 Reply Last reply
                1
                • jsulmJ jsulm

                  @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

                  Pranit PatilP Offline
                  Pranit PatilP Offline
                  Pranit Patil
                  wrote on 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.

                  jsulmJ 1 Reply Last reply
                  0
                  • Pranit PatilP Pranit Patil

                    @jsulm i mention Save pdf file in Build Directory.

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on 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