PDA

View Full Version : QFile copy connect bytesWritten



realdarkman71
25th May 2011, 13:25
Hi all,

short question with simple code:


QFile from("/home/chris/backup.tar.bz2");
QFile to("/home/chris/Test/backup.tar.bz2");

connect(&to, SIGNAL(bytesWritten(qint64)), this, SLOT(onWrite(qint64)));

from.copy(to.fileName());

(...)

void MyClass::onWrite(qint64 bytes) {
qDebug() << bytes;
}


The file will be copied, but no bytes are shown! Why?

Thx!
Chris

Santosh Reddy
25th May 2011, 13:56
bytes will be copied if you copy them, i don't see any copying code.

byteWritten() i emitted when bytes are written to the file, you should connect to this signal (shich you have already done), now in the onWrite() slot, you should copy the bytes

-Reply Recalled

realdarkman71
25th May 2011, 14:27
Line 6: from.copy(to.fileName()); ?

Lesiok
25th May 2011, 14:35
Line 6: from.copy(to.fileName()); ?
1. I think that from.copy() don't use Yours to QFile object but creates new one.
2. From QFile doc : Unlike other QIODevice implementations, such as QTcpSocket, QFile does not emit the aboutToClose(), bytesWritten(), or readyRead() signals.

realdarkman71
25th May 2011, 14:58
Ups, I did not seen this hint in the doc! :(

What can I use? Any hints?

high_flyer
25th May 2011, 16:30
You try using QFileSystemWatcher on the destination QFile object.
EDIT:
This will also not work if you use QFile::copy().

What exactly do you need?

realdarkman71
25th May 2011, 17:49
...a progress bar for copy process! Not file to file, copied bytes per file!

Lesiok
25th May 2011, 18:58
Look at QtCopyDialog (http://doc.qt.nokia.com/solutions/4/qtcopydialog/index.html).

realdarkman71
25th May 2011, 21:42
Ok, thanks for the hint! :)