diff options
author | Christian Heimlich <chris@pcserenity.com> | 2020-09-19 05:53:26 -0400 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2020-09-22 00:33:54 +0200 |
commit | dfd2dbcda509835014dd9091884bf6ae62cb83b3 (patch) | |
tree | 297252b3386ce5398dcc138ccfb1ce383c25c4b4 /src | |
parent | e06e7ab09d383ca05a77f44428a0686bac311df7 (diff) |
Add reentrancy guard for processEvents() in QProgressDialog::setValue()
Current implementation of QProgressDialog always calls
QCoreApplication::processEvents() when the user calls
QProgressDialog::setValue() if the PD is modal. For most cases this is
fine, but when using a Qt::WindowModal PD with setValue() connected to
a signal in another thread using Qt::QueuedConnection a reentrancy
issue is present if setValue() is triggered too frequently as the
execution of its previous call may not have finished. If this happens
too many times in a row a stack overflow will occur.
Current documentation notes this potential issue but offers no way it
avoid it while still using QProgressDialog (user must implement a
custom dialog) without resorting to using Qt::BlockingQueuedConnection,
which unnecessarily reduces performance.
Introduces the boolean reentrancy guard "processingEvents" that is
checked before calling QCoreApplication::processEvents() in a modal
PD when setValue() is used. It is set before the first call to
processEvents() and cleared after that call returns. This ensures that
only one invocation of processEvents() is possible from within
setValue() at a time, and thereby minimizes iterations of the main event
loop and eliminates the aforementioned stack overflow condition.
See - https://forum.qt.io/topic/118292/
Fixes: QTBUG-10561
Change-Id: Ifa9b91cbb66881981356954ead0906bdc91fab60
Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch>
(cherry picked from commit 10bc093d4fa1889b7a5f6151c9bcc79aa31ecfc5)
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/widgets/dialogs/qprogressdialog.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/widgets/dialogs/qprogressdialog.cpp b/src/widgets/dialogs/qprogressdialog.cpp index 40548e22a5..c4962b0e64 100644 --- a/src/widgets/dialogs/qprogressdialog.cpp +++ b/src/widgets/dialogs/qprogressdialog.cpp @@ -49,6 +49,7 @@ #include "qpushbutton.h" #include "qtimer.h" #include "qelapsedtimer.h" +#include "qscopedvaluerollback.h" #include <private/qdialog_p.h> #include <limits.h> @@ -69,6 +70,7 @@ public: shown_once(false), cancellation_flag(false), setValue_called(false), + processingEvents(false), showTime(defaultShowTime), #ifndef QT_NO_SHORTCUT escapeShortcut(nullptr), @@ -92,6 +94,7 @@ public: bool shown_once; bool cancellation_flag; bool setValue_called; + bool processingEvents; QElapsedTimer starttime; int showTime; bool autoClose; @@ -658,8 +661,10 @@ void QProgressDialog::setValue(int progress) d->bar->setValue(progress); if (d->shown_once) { - if (isModal()) + if (isModal() && !d->processingEvents) { + const QScopedValueRollback<bool> guard(d->processingEvents, true); QCoreApplication::processEvents(); + } } else { if ((!d->setValue_called && progress == 0 /* for compat with Qt < 5.4 */) || progress == minimum()) { d->starttime.start(); |