Results 1 to 5 of 5

Thread: asynchronous file copy

  1. #1
    Join Date
    Jun 2009
    Posts
    66
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default asynchronous file copy

    Hi All,

    Does anyone know of a way to perform an asynchronous copy of a file on a system from 'directory A' to 'directory B', without putting a call to the QFile copy command in a thread. I know i could do this, but i'm wondering whether i've missed a qt function which can do this already. I need to do this because ive got large files to copy, and want to stop my app's GUI from freezing.

    regards,

    David

  2. #2
    Join Date
    Jan 2010
    Posts
    73
    Thanks
    6
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: asynchronous file copy

    I cannot comment on any QT specific solutions, but, I have done this sort multiple times. This provided the following advantages:

    1. Properly architected, the solution is interruptable. When I used built-in copy methods, they were not. This allowed me to abort a long copy with no problems.
    2. If desired, you can easily provide status callbacks. I allowed for callbacks on start and completion of each file. This includes error information if it makes sense.
    3. I frequently gather some sort of file fingerprint / hash during the copy. Calculating an MD5 hash in-line did not add any perceivable time to the copy.


    I cannot claim that my solution was any faster than any built-in method, but it was not slower either. In other words, it provided advantages with no disadvantages (other than the fact that I needed to write code).

  3. #3
    Join Date
    Jan 2008
    Location
    Bengaluru
    Posts
    144
    Thanks
    8
    Thanked 7 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: asynchronous file copy

    Create a worker thread and put your file copy operations inside it. Create a SIGNAL, SLOT which connect main and the worker thread for any file completion, status. Does it help ?

  4. #4
    Join Date
    Jun 2009
    Posts
    66
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: asynchronous file copy

    Hi nikhilqt,

    I certainly thing your suggestion is the way to go, although i'm now thinking the bottleneck in my app may be where i sporn out to an external process to extract some files, before the copy. Doing some tests on my code to confirm this, and then i'll have to do a similar thing with that.

    regards,

    David

  5. #5
    Join Date
    Jun 2009
    Posts
    66
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Smile Re: asynchronous file copy

    I realised that the GUI freeze was caused by copying a large number of small files in serial, and not because of copying 1 large file. Therefore after copying each small file, I call QApplication:rocessEvents(), to process any events in the queue. This improved the app's responsiveness.

    Now now i'm checking my app for other occurances of this.

    cheers for everyones help.

    David

Similar Threads

  1. Copy a log file
    By fortyhideout12 in forum Qt Programming
    Replies: 2
    Last Post: 15th August 2009, 08:05
  2. Copy a File with QT
    By undercover in forum Newbie
    Replies: 3
    Last Post: 13th February 2009, 16:33
  3. copy XML file
    By mattia in forum Newbie
    Replies: 1
    Last Post: 8th February 2008, 13:30
  4. Copy a file?
    By whitefurrows in forum Qt Programming
    Replies: 2
    Last Post: 27th July 2007, 21:05
  5. file copy in Qt 3.3.4 ?
    By npc in forum Newbie
    Replies: 6
    Last Post: 31st March 2006, 14:43

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.