hi,
how can i make a progress bar count time?
I have an operation that needs 2.5 minutes to complete and i want a progress bar to count this time....
any ideas??:confused:
N.A
Printable View
hi,
how can i make a progress bar count time?
I have an operation that needs 2.5 minutes to complete and i want a progress bar to count this time....
any ideas??:confused:
N.A
What if you run it on another computer and it will take 3 minutes or 1 minute?
QProgressBar is used to display the completed amount of a certain process.
Anyway, if you really want to do this, us a QTimer and update the progress bar every 10 secs or so. You will know that 2.5 minutes have passed by computing the time difference between when the QTimer started and the QTimer stopped.
Something like this:
Code:
void Class::timeoutSlot() { if( elapsed / 60.0f >= 2.5f ) { //This means 2.5 mins have elapsed } else { mProgressBar->setValue( mProgressBar->value() + 10 ); } }
Above mStartTime is a QTime::currentTime created when you start your progress created when, and your QTimer has a 10 seconds timeout with its timeout signal connected to timeoutSlot().
Regards
I suggest using QTimeLine. You can then easily choose the update period.
Code:
tl->setDuration(150000); tl->setRange(0, 150); // update every second tl->setLoopCount(1); pb->setRange(0, 150); // the same as for the time line connect(tl, SIGNAL(frameChanged(int)), pb, SLOT(setValue(int))); pb->setValue(0); connect(tl, SIGNAL(finished()), tl, SLOT(deleteLater())); // cleanup tl->start();
Yes, better...
thanks for the answer, the operation virtually lasts for 2,5 minutes {it emulates time} so that's why i wanted it!