PDA

View Full Version : Copy progress bar



safknw
12th August 2006, 09:46
Hi,
I need a file copy progress bar.
If (any body has)
{ pls send it to me; }
else
{
how to copy file byte by byte in Qt ;
how to keep file copy and progress bar in sync;
}

wysota
12th August 2006, 10:54
QUrlOperator, QProgressDialog.

Copying byte by byte is very slow, it is better to use OS system calls to do that (at least through QFile::copy), but if you insist, something like this should work:


QFile src("srcfile");
QFile dst("dstfile");
if(!src.open(QFile::ReadOnly) || !dst.open(QFile::WriteOnly)) return;
QProgressDialog *dlg = new QProgressDialog(this);
qint64 len = src.bytesAvailable();
dlg->setRange(0,len);
dlg->show();
char ch;
while(!src.atEnd()){
src.getChar(&ch);
dst.putChar(ch);
dlg->setValue(dlg->value()+1);
qApp->processEvents();
}

safknw
12th September 2006, 14:04
Is there any other way to copy file manually in Qt3.

wysota
12th September 2006, 14:39
What do you mean by "other" and "manually"? What's wrong with regular methods?

safknw
13th September 2006, 12:25
What do you mean by "other" and "manually"? What's wrong with regular methods?
By "other" I mean other than above method (that u specify) to copy file. By manually I not using system calls.

sunil.thaha
13th September 2006, 14:12
What is wrong with QUrlOperator::copy() (http://doc.trolltech.com/3.1/qurloperator.html#copy) and connect to dataTransferred()

wysota
13th September 2006, 14:55
By "other" I mean other than above method (that u specify) to copy file. By manually I not using system calls.

The method with reading and writing byte by byte doesn't satisfy you too?

safknw
15th September 2006, 11:54
It is quit slow, specially when u have to copy 80-100 Gb file.

sunil.thaha
15th September 2006, 12:00
When you want to copy a file about 80-100 GB in size, why do you want to copy Byte by Byte ? Why not in a block ?

And what is wrong with the Qt's copy functions ?

wysota
15th September 2006, 12:04
It is quit slow, specially when u have to copy 80-100 Gb file.
That's why they invented system calls that copy files without the need to transfer every byte of the file to userspace. If you don't want to use them, you have to stick with copying every byte of the file yourself (it will be slow no matter if you copy byte by byte or kilobyte by kilobyte).

safknw
15th September 2006, 13:11
When you want to copy a file about 80-100 GB in size, why do you want to copy Byte by Byte ? Why not in a block ?

And what is wrong with the Qt's copy functions ?
Block by Block is OK but how.
Qt'copy functions is not availble in Qt 3.3.x

wysota
15th September 2006, 13:27
Qt'copy functions is not availble in Qt 3.3.x

Are you sure?
QUrlOperator::copy()

safknw
16th September 2006, 08:30
My problem is that I have read the data from file, cypher/encrypt some part of it then save it to other file. I have to show the progress bar while doing this.

wysota
16th September 2006, 09:02
So is the problem about copying the file or showing the progress bar? QProgressDialog has all you need if latter is the case.