PDA

View Full Version : Copy files+ progress



Fastman
22nd October 2007, 16:21
For copying files I use a following code :


qint16 CWorkFiles::CopyFile(QString cSrc, QString cDst)
{
//QApplication::beep();
if (!copy(cSrc,cDst))
return -1;
emit finished();
return 1;
}

how to receive percent of copying?

DeepDiver
22nd October 2007, 16:41
I don't know of any Qt-way to do so - looks like you need to implement this functionality yourself and emit signal on what ever granularity you like.
I see two possible implementation:

1.) Open the source file, read the content in chunks to the app's memory and write the content to the target.
This will work on all platforms, but is it will take much longer compared to a direct os-call.

2.) Use os-specific functions to do so. On win32 you can use: CopyFileEx (http://msdn2.microsoft.com/en-us/library/aa363852.aspx).
You need to write code for all platforms you'd like to support.

Good luck,

Tom

Fastman
22nd October 2007, 18:01
I don't know of any Qt-way to do so - looks like you need to implement this functionality yourself and emit signal on what ever granularity you like.
I see two possible implementation:

1.) Open the source file, read the content in chunks to the app's memory and write the content to the target.
This will work on all platforms, but is it will take much longer compared to a direct os-call.

Yes, but i am have big files(5-30Gb) :)



2.) Use os-specific functions to do so. On win32 you can use: CopyFileEx (http://msdn2.microsoft.com/en-us/library/aa363852.aspx).
You need to write code for all platforms you'd like to support.

:( is a not crossplatform



Good luck,
Tom

Thank for you answer :)

wysota
22nd October 2007, 18:37
The most Qt-ish (but definitely not the fastest) way to do it is to use an object that will open source and destination file and perform a loop of reading a blob of data, writing it to the destination and emitting a signal reporting the progress. You can implement it around QIODevice::bytesWritten to make it asynchronous. A quicker but more dirty way would be to use fast platform dependent API like sendFile() on Linux (that doesn't copy data to userspace) in a thread and use QFileSystemWatcher to watch progress of the copy operation.