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 copy a pdf to specific Directory and rename it
Forum Updated to NodeBB v4.3 + New Features

How to copy a pdf to specific Directory and rename it

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 5 Posters 3.3k Views 2 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.
  • T TMJJ001

    Hi all,

    Thanks for the quick reply. It gave me already a good way to go.
    Now It think I do something stupid. This is my code.

        maintenanceType = ui->maintenanceType_Combo->currentText();
        reductionSN = ui->ReductionSN_lineEdit->text();
        resp = ui->resp_lineEdit->text();
        dateMydate = ui->dateEdit_maintenance->date();
    
        QString Date = dateMydate.toString("dd/MM/yyyy");
    
        QString pdfPath = QFileDialog::getOpenFileName(this,tr("Search report"), "C://", "PDF (*.pdf)");
        QMessageBox::information(this,tr("Load report"),pdfPath);
    
    
        QString name = reductionSN + " -- " + Date + " -- " + maintenanceType + " -- " + resp + ".pdf";
        qDebug()<<name;
        QString newPath = "//SARWOLVM180/Technical Documentation/Kranen/Algemeen/10 Jaarlijkse inspectie/Database/Report/" + name ;
        qDebug()<<newPath;
        bool success = QFile::copy(pdfPath,newPath);
    
        qDebug()<<success;
    
    

    When I run this I get the following output:

    When I push the addMaintenance button I get the following output

    mincore\com\oleaut32\dispatch\ups.cpp(2128)\OLEAUT32.dll!74BD5072: (caller: 74BDFE4F) ReturnHr(1) tid(cd8) 8002801D Library not registered.
    shell\comdlg32\fileopensave.cpp(14267)\comdlg32.dll!74647C7D: (caller: 746768FC) ReturnHr(1) tid(cd8) 80004005 Unspecified error
        CallContext:[\PickerModalLoop] 
    

    When I click OK on the messagebox I get the following output:

    "72802057740 -- 27/02/2018 -- Oil change -- MMM.pdf"
    "//SARWOLVM180/Technical Documentation/Kranen/Algemeen/10 Jaarlijkse inspectie/Database/Report/72802057740 -- 27/02/2018 -- Oil change -- MMM.pdf"
    false
    

    So the file doesn't get copied at all.
    Now I was wondering is the in the first step or the second step?

    Anybody a clue?

    Thanks in advance,
    Kind regards

    raven-worxR Offline
    raven-worxR Offline
    raven-worx
    Moderators
    wrote on last edited by
    #5

    @TMJJ001
    does the directory //SARWOLVM180/Technical Documentation/Kranen/Algemeen/10 Jaarlijkse inspectie/Database/Report/ already exist?
    I am not sure if QFile::copy() takes care of this.

    It may be that you need to ensure that the target path is already created:

    QFileInfo(filePath).absoluteDir().mkpath(".")
    

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

    T 1 Reply Last reply
    0
    • raven-worxR raven-worx

      @TMJJ001
      does the directory //SARWOLVM180/Technical Documentation/Kranen/Algemeen/10 Jaarlijkse inspectie/Database/Report/ already exist?
      I am not sure if QFile::copy() takes care of this.

      It may be that you need to ensure that the target path is already created:

      QFileInfo(filePath).absoluteDir().mkpath(".")
      
      T Offline
      T Offline
      TMJJ001
      wrote on last edited by
      #6

      @raven-worx

      Yes the directory does already excists. This is the directory to my server.
      I copied some files to this dir manually and I can access them with the following code:

      QDesktopServices::openUrl(QUrl::fromLocalFile(RP));
      

      Where RP is the following:

      \\SARWOLVM180\Technical Documentation\Kranen\Algemeen\10 Jaarlijkse inspectie\Database\Report\72802057740 -- 19012018 -- Rebuild -- BoschRexroth.pdf
      

      So I don't think this is the issue

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bludger
        wrote on last edited by
        #7

        Does the application or the context wherein it lives have the correct rights to create files ?
        Another thing what you could try is to convert the forward slashes to backward slashes. You can use the following function to do that: QDir::toNativeSeperators()

        T 1 Reply Last reply
        0
        • B bludger

          Does the application or the context wherein it lives have the correct rights to create files ?
          Another thing what you could try is to convert the forward slashes to backward slashes. You can use the following function to do that: QDir::toNativeSeperators()

          T Offline
          T Offline
          TMJJ001
          wrote on last edited by
          #8

          @bludger

          The application has the correct right to create files. I also tried the QDir::toNativeSeperators() without success.
          I get the same errors outputs.

          1 Reply Last reply
          0
          • B Offline
            B Offline
            bludger
            wrote on last edited by
            #9

            @TMJJ001 said in How to copy a pdf to specific Directory and rename it:

            "//SARWOLVM180/Technical Documentation/Kranen/Algemeen/10 Jaarlijkse inspectie/Database/Report/72802057740 -- 27/02/2018 -- Oil change -- MMM.pdf"

            You're using slashes for the date notation, you should use dashes instead. That should fix it.
            Graag gedaan.

            raven-worxR T 2 Replies Last reply
            3
            • B bludger

              @TMJJ001 said in How to copy a pdf to specific Directory and rename it:

              "//SARWOLVM180/Technical Documentation/Kranen/Algemeen/10 Jaarlijkse inspectie/Database/Report/72802057740 -- 27/02/2018 -- Oil change -- MMM.pdf"

              You're using slashes for the date notation, you should use dashes instead. That should fix it.
              Graag gedaan.

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by raven-worx
              #10

              @bludger said in How to copy a pdf to specific Directory and rename it:

              You're using slashes for the date notation, you should use dashes instead. That should fix it.

              dashes are -, if you mean backslashes \ also no. Qt (QFile at least) supports // for UNC paths.

              --- 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
              0
              • B Offline
                B Offline
                bludger
                wrote on last edited by
                #11

                @raven-worx I'm aware of that but if you take a close look at his code you see the following:
                QString Date = dateMydate.toString("dd/MM/yyyy");

                The Date object is being used to compose the destination filename as seen here:
                QString name = reductionSN + " -- " + Date + " -- " + maintenanceType + " -- " + resp + ".pdf";

                As he showed in an earlier post the destination path becomes this:
                "//SARWOLVM180/Technical Documentation/Kranen/Algemeen/10 Jaarlijkse inspectie/Database/Report/72802057740 -- 27/02/2018 -- Oil change -- MMM.pdf"

                Since he doesn't do mkpath before the file copy there is a big chance that the folder Report/ doesn't contain a directory named: 72802057740 -- 27 which contains 02 as subdir and that one haves 2018 as subdir.

                So if he use dashes instead of slashes to get the Date object to copy will probably work. Another way is to create the complete directory structure using the mkpath function.

                raven-worxR 1 Reply Last reply
                3
                • B bludger

                  @TMJJ001 said in How to copy a pdf to specific Directory and rename it:

                  "//SARWOLVM180/Technical Documentation/Kranen/Algemeen/10 Jaarlijkse inspectie/Database/Report/72802057740 -- 27/02/2018 -- Oil change -- MMM.pdf"

                  You're using slashes for the date notation, you should use dashes instead. That should fix it.
                  Graag gedaan.

                  T Offline
                  T Offline
                  TMJJ001
                  wrote on last edited by
                  #12

                  @bludger

                  Yes this was the problem!! Stupid !!

                  Thanks all for helping!
                  Dank u wel allemaal ;)

                  Kind regards

                  1 Reply Last reply
                  0
                  • B bludger

                    @raven-worx I'm aware of that but if you take a close look at his code you see the following:
                    QString Date = dateMydate.toString("dd/MM/yyyy");

                    The Date object is being used to compose the destination filename as seen here:
                    QString name = reductionSN + " -- " + Date + " -- " + maintenanceType + " -- " + resp + ".pdf";

                    As he showed in an earlier post the destination path becomes this:
                    "//SARWOLVM180/Technical Documentation/Kranen/Algemeen/10 Jaarlijkse inspectie/Database/Report/72802057740 -- 27/02/2018 -- Oil change -- MMM.pdf"

                    Since he doesn't do mkpath before the file copy there is a big chance that the folder Report/ doesn't contain a directory named: 72802057740 -- 27 which contains 02 as subdir and that one haves 2018 as subdir.

                    So if he use dashes instead of slashes to get the Date object to copy will probably work. Another way is to create the complete directory structure using the mkpath function.

                    raven-worxR Offline
                    raven-worxR Offline
                    raven-worx
                    Moderators
                    wrote on last edited by
                    #13

                    @bludger said in How to copy a pdf to specific Directory and rename it:

                    I'm aware of that but if you take a close look at his code you see the following:
                    QString Date = dateMydate.toString("dd/MM/yyyy");

                    ah yes, didnt get that you actually meant the date in the path

                    --- 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
                    1
                    • sierdzioS Offline
                      sierdzioS Offline
                      sierdzio
                      Moderators
                      wrote on last edited by
                      #14

                      Sorry to chime in, I just want to verify: it works? If yes then it means Qt does now support copying to samba shares, cool :-)

                      (Z(:^

                      1 Reply Last reply
                      1

                      • Login

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