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. File Copy Question
Forum Update on Monday, May 27th 2025

File Copy Question

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 4 Posters 3.2k Views
  • 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.
  • C Offline
    C Offline
    Crag_Hack
    wrote on last edited by Crag_Hack
    #1

    Hi I am writing a file replicator program that replicates the contents of a source directory to a destination directory.

    The copy progress is not consistent when copying from a system SSD to a backup mechanical drive. It will copy a good 100 MB or so then pause a fifth of a second or so then start up again. I get the same results disabling AV and firewall. When reading from the SSD only without doing any file writing it's consistent. When going from backup drive to system SSD it is consistent as well.

    On another Vista system when copying from the slow computer to a flash drive it pauses every couple seconds I suspect to clear some blocks for writing but other than that it behaves normally. When copying from network to a Vista computer drive the copy is consistent.

    I suspect the first inconsistency is due to the lack of buffering during file copying. My current copy code is below. buffer is a QByteArray and targetTempFile is a QFile. The count integer is just leftover from a previous implementation.

    How come QT doesn't provide progress tracking with the bytesWritten() signal for QFile copying? It looks like this code just bouncing back and forth between reading the source and writing the target right? Do you think a read/write buffer would maximize performance and provide more consistent copy peformance? I found this guy - it appears this function is buffered correct? If so and there are no complications I will give it a go. Anything else to know? Thanks!

            for (int count = 0; !(buffer = sourceFile.read(1000000)).isEmpty() && cancel == false; count++)
            {
                int readSize = buffer.size();
                targetTempFile.write(buffer);
                if (advanced = true)
                    setAdvancedProgressMeters(readSize, sourceFile.size(), job.getSize());
                setAdvancedTimeLabels(startTime.elapsed());
            }
    
    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by A Former User
      #2

      Hi! You can just use bool QFile::copy(const QString &fileName, const QString &newName) [static].

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Crag_Hack
        wrote on last edited by
        #3

        Thanks but how do I track copy progress with that function?

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

          Hi,

          There's no monitoring you can do with that one.

          In any case, expecting that the behaviour should be the same accros all types of media and network etc. is wrong. The drives themselves have buffers, you also have to into account the bus used to communicate with your different disk, the drivers, the system load, the OS type, the speed of the hard drive motors, etc. All these factors and others can alter the speed of copy.

          [edit: fixed missing no...]

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

          1 Reply Last reply
          1
          • C Offline
            C Offline
            Crag_Hack
            wrote on last edited by Crag_Hack
            #5

            How do I monitor/track progress that one?

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

              Sorry, there was a missing no in that sentence.

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

              1 Reply Last reply
              0
              • C Offline
                C Offline
                Crag_Hack
                wrote on last edited by Crag_Hack
                #7

                Do you think a buffered IO operation might perform better though instead of bouncing back and forth between reading/writing data? I think like a producer/consumer type of thing.

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

                  It's basically the same expect that you split the operation between two threads. Though it's worth to try if only to benchmark.

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

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    Crag_Hack
                    wrote on last edited by Crag_Hack
                    #9

                    How come QFile copy doesn't emit the writesbytten signal? Also with a producer consumer buffer there'd be concurrent read/writes don't you think it'd raise performance significantly perhaps almost by a factor of 2?

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

                      Because that wouldn't make sense. bitesWritten is for when you write in a device. With a copy QFile writes in another device.

                      Again: benchmark. Parallelising disk write doesn't necessarily means that you'll double anything. If you have only one disk on the receiving side, writing twice as much data in parallel won't have the performance boost you'd expect.

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

                      1 Reply Last reply
                      0
                      • mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        Hi
                        Just as a note:
                        If i was to write anything for file copy on the windows platform
                        i would look in this tool source
                        https://ipmsg.org/tools/fastcopy.html.en

                        I use it to copy array of mirrors ( 8 TB ) to different backup locations and
                        fastcopy delivers flawless and in high speed. :)

                        1 Reply Last reply
                        1
                        • C Offline
                          C Offline
                          Crag_Hack
                          wrote on last edited by
                          #12

                          Thanks mrjj definitely worth checking out.

                          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