[Interest] QProgressDialog not showing & processEvents()
David Faure
david.faure at kdab.com
Wed Nov 20 12:30:34 CET 2013
On Monday, November 18, 2013 08:09:41 AM André Somers wrote:
> It is *not* called by setValue. That is a Good Thing(TM).
I strongly encourage reading code or documentation before making such
answers...
\warning If the progress dialog is modal
(see QProgressDialog::QProgressDialog()),
setValue() calls QApplication::processEvents(), so take care that
this does not cause undesirable re-entrancy in your code. For example,
don't use a QProgressDialog inside a paintEvent()!
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 {
[...]
}
This is not a bug however, it's the expected use case for QProgressDialog.
The usually-very-dangerous processEvents() is only midly dangerous because we
are "protected by the progress dialog", i.e. the user cannot close the
mainwindow, for instance. But of course, timers and sockets could still
trigger code that deletes objects etc.
In any case - to come back to the initial question: did you call setValue(0)
upfront?
I just pushed a review request for this to happen automatically, but it's not
merged yet. https://codereview.qt-project.org/71619
--
David Faure | david.faure at kdab.com | Managing Director KDAB France
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, Sweden (HQ) +46-563-540090
KDAB - Qt Experts - Platform-independent software solutions
More information about the Interest
mailing list