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. Copy of large files and QFileSystemWatcher under windows
Forum Updated to NodeBB v4.3 + New Features

Copy of large files and QFileSystemWatcher under windows

Scheduled Pinned Locked Moved Solved General and Desktop
23 Posts 5 Posters 7.7k 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    When copying large files, I usually avoid letting QFile do that alone. I usually do the read/write operation by hand to allow for better feedback and GUI responsiveness.

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

    C 1 Reply Last reply
    0
    • SGaistS SGaist

      Hi,

      When copying large files, I usually avoid letting QFile do that alone. I usually do the read/write operation by hand to allow for better feedback and GUI responsiveness.

      C Offline
      C Offline
      calebhalvy
      wrote on last edited by
      #3

      @SGaist What do you mean do the read/write operation by hand?

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

        Yes, I use QFile for the read and write part.

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

        S 1 Reply Last reply
        0
        • SGaistS SGaist

          Yes, I use QFile for the read and write part.

          S Offline
          S Offline
          stephane78
          wrote on last edited by stephane78
          #5

          @SGaist It is not copy by programming.
          I have an app made with QFileSystemWatcher(a file synchronization app) that monitors and watches a directory and when I run the app and that I copy a large file into the watched directory, the signal directoryChanged of QFileSystemWtacher is emitted at the beginning of the copy of the large file and it should be at the end of the copy of the large file ...that's my problem

          jsulmJ 1 Reply Last reply
          0
          • S stephane78

            @SGaist It is not copy by programming.
            I have an app made with QFileSystemWatcher(a file synchronization app) that monitors and watches a directory and when I run the app and that I copy a large file into the watched directory, the signal directoryChanged of QFileSystemWtacher is emitted at the beginning of the copy of the large file and it should be at the end of the copy of the large file ...that's my problem

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #6

            @stephane78 said in Copy of large files and QFileSystemWatcher under windows:

            it should be at the end of the copy of the large file

            Why do you think it should? I know, you need it at the end, but maybe someone else needs it at the beginning.

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

            1 Reply Last reply
            0
            • VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #7

              The only two things I can think of are:

              • try KDirNotify instead
              • Afetr you get the "beginning of copy" signal, store the file size, start a QTimer (500ms?) and check the file size again, if they are equal it probably is finished. I know it's not optimal

              "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

              S 1 Reply Last reply
              3
              • VRoninV VRonin

                The only two things I can think of are:

                • try KDirNotify instead
                • Afetr you get the "beginning of copy" signal, store the file size, start a QTimer (500ms?) and check the file size again, if they are equal it probably is finished. I know it's not optimal
                S Offline
                S Offline
                stephane78
                wrote on last edited by stephane78
                #8

                @VRonin Thank you VRonin, but how can I use KDirNotify because I am under windows (the main version of this app must run under windows although there will be perhaps a mac and linux version too) and KDE runs under linux.
                for the solution with the timer I will perhaps try it...thanks

                1 Reply Last reply
                0
                • VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by VRonin
                  #9

                  The KDE API has been rewritten in version 5 to be platform independent. The KIO module (which contains KDirNoitify) runs on all desktop platforms (i.e. not on android) by default

                  "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

                  S 1 Reply Last reply
                  3
                  • VRoninV VRonin

                    The KDE API has been rewritten in version 5 to be platform independent. The KIO module (which contains KDirNoitify) runs on all desktop platforms (i.e. not on android) by default

                    S Offline
                    S Offline
                    stephane78
                    wrote on last edited by
                    #10

                    @VRonin thanks I didn't know it. and I should compile the KIO module or library and link it with my app ? I have looked at the url and it seems it uses QtDbus. Can I use QtDbus under windows too? and the signals that are emitted seem to be for files and not for directories ? or is it for directories too ?
                    it seems although more powerful that QfileSystemWatcher, because there are only two signals emitted by QfileSystemWatcher directoryChanged and fileChanged, that's why, I have added code in a class to process all the cases...

                    S 1 Reply Last reply
                    0
                    • S stephane78

                      @VRonin thanks I didn't know it. and I should compile the KIO module or library and link it with my app ? I have looked at the url and it seems it uses QtDbus. Can I use QtDbus under windows too? and the signals that are emitted seem to be for files and not for directories ? or is it for directories too ?
                      it seems although more powerful that QfileSystemWatcher, because there are only two signals emitted by QfileSystemWatcher directoryChanged and fileChanged, that's why, I have added code in a class to process all the cases...

                      S Offline
                      S Offline
                      stephane78
                      wrote on last edited by
                      #11

                      @VRonin Hi it is the class KDirWatch that does that (link text (Ihave asked to the developper of KIO)
                      I will try this class KDirWatch....

                      S 1 Reply Last reply
                      0
                      • S stephane78

                        @VRonin Hi it is the class KDirWatch that does that (link text (Ihave asked to the developper of KIO)
                        I will try this class KDirWatch....

                        S Offline
                        S Offline
                        stephane78
                        wrote on last edited by
                        #12

                        @VRonin, I have watched the code of KDirWatch but I think it doesn't solve my problem, so I will try to use your solution with the timer...;thanks

                        S 1 Reply Last reply
                        0
                        • S stephane78

                          @VRonin, I have watched the code of KDirWatch but I think it doesn't solve my problem, so I will try to use your solution with the timer...;thanks

                          S Offline
                          S Offline
                          stephane78
                          wrote on last edited by
                          #13

                          @VRonin, I have a question before testing, does QFile::size() return the actual size of the large file being copied (so not complete) or does it return 0 ?

                          1 Reply Last reply
                          0
                          • VRoninV Offline
                            VRoninV Offline
                            VRonin
                            wrote on last edited by VRonin
                            #14

                            QFile does not know it's being copied so it will return the actual incomplete file size.

                            One other thing that comes to mind but I did not test is that the copy probably locks the file for writing so attempting QFile::open(QIODevice::WriteOnly) might return false

                            "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

                            S 1 Reply Last reply
                            2
                            • VRoninV VRonin

                              QFile does not know it's being copied so it will return the actual incomplete file size.

                              One other thing that comes to mind but I did not test is that the copy probably locks the file for writing so attempting QFile::open(QIODevice::WriteOnly) might return false

                              S Offline
                              S Offline
                              stephane78
                              wrote on last edited by
                              #15

                              @VRonin OK my problem is solved thanks to you. I have made it with timers.....

                              1 Reply Last reply
                              0
                              • VRoninV Offline
                                VRoninV Offline
                                VRonin
                                wrote on last edited by
                                #16

                                Can you share your final code so other users can benefit from the solution?

                                "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

                                S 1 Reply Last reply
                                0
                                • VRoninV VRonin

                                  Can you share your final code so other users can benefit from the solution?

                                  S Offline
                                  S Offline
                                  stephane78
                                  wrote on last edited by stephane78
                                  #17

                                  @VRonin not all my code because it is a for a Saas software of my company that will be copyrighted (we use Qt-LGPL)...But I can say something important : the condition to test the end of the copy of the large file (in the slot connected to the timeout ) is the equality of previous size and current size and QFile::open(QIODevice::ReadOnly).In my case I use ReadOnly because I use the file and read it after again to use it and it is ok. and it works.a third condition that I have putted in the test is that the current size is not equal 0 because I believe that QFile::size() return 0 so long the file is not finished copied but I am not sure of this condition but if I remove it, I have a visual c++ runtime error that comes .
                                  so you have the three conditions of the test of the end of the copy of the large file and it is the most important.
                                  the left is specific to my software.
                                  but When I detect a new file added thanks to QFileSYstemWatcher I create a new object with the path of the file and in the constructor of this object I create a timer and start it.so for each file added in the directory there is a new timer that will be deleted later after use of this object linked to the file.....
                                  so there are enough hints now to make the things....

                                  S 1 Reply Last reply
                                  1
                                  • S stephane78

                                    @VRonin not all my code because it is a for a Saas software of my company that will be copyrighted (we use Qt-LGPL)...But I can say something important : the condition to test the end of the copy of the large file (in the slot connected to the timeout ) is the equality of previous size and current size and QFile::open(QIODevice::ReadOnly).In my case I use ReadOnly because I use the file and read it after again to use it and it is ok. and it works.a third condition that I have putted in the test is that the current size is not equal 0 because I believe that QFile::size() return 0 so long the file is not finished copied but I am not sure of this condition but if I remove it, I have a visual c++ runtime error that comes .
                                    so you have the three conditions of the test of the end of the copy of the large file and it is the most important.
                                    the left is specific to my software.
                                    but When I detect a new file added thanks to QFileSYstemWatcher I create a new object with the path of the file and in the constructor of this object I create a timer and start it.so for each file added in the directory there is a new timer that will be deleted later after use of this object linked to the file.....
                                    so there are enough hints now to make the things....

                                    S Offline
                                    S Offline
                                    stephane78
                                    wrote on last edited by
                                    #18

                                    @VRonin, I have tested it with a 1,85 Gb file because we are limited to 2Gb files....

                                    1 Reply Last reply
                                    0
                                    • VRoninV Offline
                                      VRoninV Offline
                                      VRonin
                                      wrote on last edited by
                                      #19

                                      on the file size =0 I think it's my fault as the docs clearly state:

                                      if the device is closed, the size returned will not reflect the actual size of the device.

                                      so before QFile::open() ,QFile::size() is meaningless

                                      "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

                                      S 1 Reply Last reply
                                      0
                                      • VRoninV VRonin

                                        on the file size =0 I think it's my fault as the docs clearly state:

                                        if the device is closed, the size returned will not reflect the actual size of the device.

                                        so before QFile::open() ,QFile::size() is meaningless

                                        S Offline
                                        S Offline
                                        stephane78
                                        wrote on last edited by stephane78
                                        #20

                                        @VRonin so my test is not really correct, I have now read that too in the documentation. because my test is :
                                        if (currentsize&&currentsize==oldsize&&f.open(QIODevice::ReadOnly))

                                        //(and currentsize=f.size();)

                                        S 1 Reply Last reply
                                        0
                                        • S stephane78

                                          @VRonin so my test is not really correct, I have now read that too in the documentation. because my test is :
                                          if (currentsize&&currentsize==oldsize&&f.open(QIODevice::ReadOnly))

                                          //(and currentsize=f.size();)

                                          S Offline
                                          S Offline
                                          stephane78
                                          wrote on last edited by
                                          #21

                                          @VRonin it is ok with this test but not perfect, I suppose currentsize=0 and f.open returns false so long the copy is not finished

                                          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