PDA

View Full Version : asynchronous file copy



doggrant
2nd February 2010, 15:51
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

pitonyak
2nd February 2010, 22:53
I cannot comment on any QT specific solutions, but, I have done this sort multiple times. This provided the following advantages:


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

nikhilqt
3rd February 2010, 07:11
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 ?

doggrant
4th February 2010, 13:10
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

doggrant
5th February 2010, 10:13
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::processEvents(), 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