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.4k 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.
  • V Offline
    V Offline
    VRonin
    wrote on 23 Jan 2017, 09:44 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 23 Jan 2017, 09:59
    3
    • V VRonin
      23 Jan 2017, 09:44

      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 23 Jan 2017, 09:59 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 23 Jan 2017, 11:35
      0
      • S stephane78
        23 Jan 2017, 09:59

        @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 23 Jan 2017, 11:35 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 23 Jan 2017, 14:36
        0
        • S stephane78
          23 Jan 2017, 11:35

          @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 23 Jan 2017, 14:36 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 24 Jan 2017, 10:16
          0
          • S stephane78
            23 Jan 2017, 14:36

            @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 24 Jan 2017, 10:16 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
            • V Offline
              V Offline
              VRonin
              wrote on 24 Jan 2017, 10:19 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 25 Jan 2017, 13:52
              2
              • V VRonin
                24 Jan 2017, 10:19

                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 25 Jan 2017, 13:52 last edited by
                #15

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

                1 Reply Last reply
                0
                • V Offline
                  V Offline
                  VRonin
                  wrote on 25 Jan 2017, 14:36 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 25 Jan 2017, 15:34
                  0
                  • V VRonin
                    25 Jan 2017, 14:36

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

                    S Offline
                    S Offline
                    stephane78
                    wrote on 25 Jan 2017, 15:34 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 25 Jan 2017, 15:38
                    1
                    • S stephane78
                      25 Jan 2017, 15:34

                      @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 25 Jan 2017, 15:38 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
                      • V Offline
                        V Offline
                        VRonin
                        wrote on 25 Jan 2017, 15:38 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 25 Jan 2017, 15:44
                        0
                        • V VRonin
                          25 Jan 2017, 15:38

                          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 25 Jan 2017, 15:44 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 25 Jan 2017, 15:47
                          0
                          • S stephane78
                            25 Jan 2017, 15:44

                            @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 25 Jan 2017, 15:47 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
                            • V Offline
                              V Offline
                              VRonin
                              wrote on 25 Jan 2017, 15:51 last edited by
                              #22

                              I would use:

                              bool check = f.open(QIODevice::ReadOnly);
                              check = check && currentsize==oldsize
                              if(check)
                              

                              "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 25 Jan 2017, 16:45
                              1
                              • V VRonin
                                25 Jan 2017, 15:51

                                I would use:

                                bool check = f.open(QIODevice::ReadOnly);
                                check = check && currentsize==oldsize
                                if(check)
                                
                                S Offline
                                S Offline
                                stephane78
                                wrote on 25 Jan 2017, 16:45 last edited by stephane78
                                #23

                                @VRonin I have made several tests with your condition :

                                bool check = f.open(QIODevice::ReadOnly);
                                currentsize=f.size();
                                check = check && currentsize==oldsize
                                if(check)
                                

                                and it is ok (for small files and larges files).so thanks I will keep it....

                                1 Reply Last reply
                                1

                                18/23

                                25 Jan 2017, 15:38

                                • Login

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