tags:

views:

37

answers:

1

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 );
}
+1  A: 

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);
}
Jakub Wieczorek
could u suggest a link that will explain this elaborately to me. this will help me digest the concept as well. thank you
knishua