diff options
author | Ahmad Samir <a.samirh78@gmail.com> | 2023-02-20 15:46:48 +0200 |
---|---|---|
committer | Ahmad Samir <a.samirh78@gmail.com> | 2023-06-30 02:24:54 +0300 |
commit | 4f618bde086ab9c823143acf99b0411ef99bd67d (patch) | |
tree | f60d07469b8e1026c76dde5891bb066c51428222 /src/corelib/kernel/qeventloop.cpp | |
parent | fa296ee1dcf4c16fb6f242cf08949485e499fec3 (diff) |
QEventLoop: port processEvents() to QDeadlineTimer
[ChangeLog][QtCore][QEventLoop] Added a processEvents() overload
that takes a QDeadlineTimer.
Task-number: QTBUG-110059
Change-Id: I239dbeec33cb4f10d1ecd44a8455e7bd808f378b
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'src/corelib/kernel/qeventloop.cpp')
-rw-r--r-- | src/corelib/kernel/qeventloop.cpp | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/corelib/kernel/qeventloop.cpp b/src/corelib/kernel/qeventloop.cpp index 7001bfa5bd..aa1f9a4801 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; } } |