QProgressDialog, bug in Qt 4.8.0 or something else ?
-
I'm using Qt 4.8.0 under Windows OS and I have the division by zero error when set value to 1:
@void QProgressDialog::setValue(int progress)
{
Q_D(QProgressDialog);
if (progress == d->bar->value()
|| (d->bar->value() == -1 && progress == d->bar->maximum()))
return;d->bar->setValue(progress); if (d->shown_once) { if (isModal()) QApplication::processEvents(); } else { if (progress == 0) { d->starttime.start(); d->forceTimer->start(d->showTime); return; } else { bool need_show; int elapsed = d->starttime.elapsed(); if (elapsed >= d->showTime) { need_show = true; } else { if (elapsed > minWaitTime) { int estimate; int totalSteps = maximum() - minimum(); int myprogress = progress - minimum(); if ((totalSteps - myprogress) >= INT_MAX / elapsed) estimate = (totalSteps - myprogress) / myprogress * elapsed; else estimate = elapsed * (totalSteps - myprogress) / myprogress; need_show = estimate >= d->showTime; } else { need_show = false; } } if (need_show) { int w = qMax(isVisible() ? width() : 0, sizeHint().width()); int h = qMax(isVisible() ? height() : 0, sizeHint().height()); resize(w, h); show(); d->shown_once = true; } }@
right here @estimate = elapsed * (totalSteps - myprogress) / myprogress;@ I have @myprogress = 0;@ As I see @int myprogress = progress - minimum();@ Where minimum() returns 1 and progress is 1. So when I'm switch to Qt 4.7.4 there is no error using QProgressDialog. So maybe it's a bug in 4.8.0 version.
-
Related to "http://developer.qt.nokia.com/forums/viewthread/8993":http://developer.qt.nokia.com/forums/viewthread/8993.
Feel free to file a "bugreport":http://developer.qt.nokia.com/doc/qt-4.8/bughowto.html. This behaviour should be fixed.
-
Here is my code where I use QProgressDialog:
@ QProgressDialog progress(tr("Save configuration to station"), tr("Abort"), 0, 0, parent);
progress.setWindowModality(Qt::WindowModal);int offset = 0; int fullSize = model.getBukDataSize(); if (transfer.startCommit() == false) { isAborted = true; hasErrors = true; } else { progress.setRange(1, fullSize+1); progress.setValue(1); int nWrong = 0; while (offset < fullSize) { qApp->processEvents(); if (progress.wasCanceled()) { isAborted = true; break; } int size = fullSize - offset; if (size > packsize) size = packsize; if (size != transfer.storeCommit(model.getBukData(), offset, size)) { if (nWrong > 10) { isAborted = true; hasErrors = true; break; } nWrong++; continue; } offset += size; progress.setValue(offset); } }@
-
So it seemed like I've got a crash when setting value to "1" : @progress.setValue(1);@ I tried to set value to zero before it, as here:http://developer.qt.nokia.com/forums/viewthread/8993 But it has no effect. One more thing: when I make some delay before calling setValue by putting sleep for 10 msecs, all working good.