Reputation: 1044
I need to increment progressbar in qt everytime a file is copied from one location to another. Example there are 64 files to be copied. How is it possible to let the progressbar know the amount to increment by. Following is help code. Could you exhaust on it.
class MyClass : ...
{
...
public slots:
void onWrite( qint64 );
};
MyClass::MyClass( ... )
{
// ...
progress->setMaximum( QFileInfo(fromFile).size() / 1024 );
written = 0;
connect( &toFile, SIGNAL(bytesWritten(qint64)), SLOT(onWrite(qint64)) );
// ...
}
void MyClass::onWrite( qint64 w )
{
written += w;
progress->setValue( written / 1024 );
}
Upvotes: 0
Views: 1399
Reputation: 1899
You can simply get the current value and add the new amount of bytes written to it.
void MyClass::onWrite(qint64 w)
{
written += w;
progress->setValue(progress->value() + written / 1024);
}
Upvotes: 1