diff --git a/src/corelib/kernel/qeventloop.cpp b/src/corelib/kernel/qeventloop.cpp index 7001bfa5bd5..aa1f9a4801d 100644 --- a/src/corelib/kernel/qeventloop.cpp +++ b/src/corelib/kernel/qeventloop.cpp @@ -6,7 +6,7 @@ #include "qabstracteventdispatcher.h" #include "qcoreapplication.h" #include "qcoreapplication_p.h" -#include "qelapsedtimer.h" +#include "qdeadlinetimer.h" #include "qobject_p.h" #include "qeventloop_p.h" @@ -186,9 +186,27 @@ int QEventLoop::exec(ProcessEventsFlags flags) } /*! + \overload + Process pending events that match \a flags for a maximum of \a maxTime milliseconds, or until there are no more events to process, whichever is shorter. + + Equivalent to calling: + \code + processEvents(flags, QDeadlineTimer(maxTime)); + \endcode +*/ +void QEventLoop::processEvents(ProcessEventsFlags flags, int maxTime) +{ + processEvents(flags, QDeadlineTimer(maxTime)); +} + +/*! + \since 6.7 + + Process pending events that match \a flags until \a deadline has expired, + or until there are no more events to process, whichever happens first. This function is especially useful if you have a long running operation and want to show its progress without allowing user input, i.e. by using the \l ExcludeUserInputEvents flag. @@ -201,16 +219,14 @@ int QEventLoop::exec(ProcessEventsFlags flags) and will be ignored. \endlist */ -void QEventLoop::processEvents(ProcessEventsFlags flags, int maxTime) +void QEventLoop::processEvents(ProcessEventsFlags flags, QDeadlineTimer deadline) { Q_D(QEventLoop); if (!d->threadData.loadRelaxed()->hasEventDispatcher()) return; - QElapsedTimer start; - start.start(); while (processEvents(flags & ~WaitForMoreEvents)) { - if (start.elapsed() > maxTime) + if (deadline.hasExpired()) break; } } diff --git a/src/corelib/kernel/qeventloop.h b/src/corelib/kernel/qeventloop.h index 387fcbbeaa4..98ad1451dd2 100644 --- a/src/corelib/kernel/qeventloop.h +++ b/src/corelib/kernel/qeventloop.h @@ -5,6 +5,7 @@ #define QEVENTLOOP_H #include +#include QT_BEGIN_NAMESPACE @@ -34,6 +35,7 @@ public: bool processEvents(ProcessEventsFlags flags = AllEvents); void processEvents(ProcessEventsFlags flags, int maximumTime); + void processEvents(ProcessEventsFlags flags, QDeadlineTimer deadline); int exec(ProcessEventsFlags flags = AllEvents); bool isRunning() const;