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>
This commit is contained in:
Ahmad Samir 2023-02-20 15:46:48 +02:00
parent fa296ee1dc
commit 4f618bde08
2 changed files with 23 additions and 5 deletions

View File

@ -6,7 +6,7 @@
#include "qabstracteventdispatcher.h" #include "qabstracteventdispatcher.h"
#include "qcoreapplication.h" #include "qcoreapplication.h"
#include "qcoreapplication_p.h" #include "qcoreapplication_p.h"
#include "qelapsedtimer.h" #include "qdeadlinetimer.h"
#include "qobject_p.h" #include "qobject_p.h"
#include "qeventloop_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 Process pending events that match \a flags for a maximum of \a
maxTime milliseconds, or until there are no more events to maxTime milliseconds, or until there are no more events to
process, whichever is shorter. 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 This function is especially useful if you have a long running
operation and want to show its progress without allowing user operation and want to show its progress without allowing user
input, i.e. by using the \l ExcludeUserInputEvents flag. input, i.e. by using the \l ExcludeUserInputEvents flag.
@ -201,16 +219,14 @@ int QEventLoop::exec(ProcessEventsFlags flags)
and will be ignored. and will be ignored.
\endlist \endlist
*/ */
void QEventLoop::processEvents(ProcessEventsFlags flags, int maxTime) void QEventLoop::processEvents(ProcessEventsFlags flags, QDeadlineTimer deadline)
{ {
Q_D(QEventLoop); Q_D(QEventLoop);
if (!d->threadData.loadRelaxed()->hasEventDispatcher()) if (!d->threadData.loadRelaxed()->hasEventDispatcher())
return; return;
QElapsedTimer start;
start.start();
while (processEvents(flags & ~WaitForMoreEvents)) { while (processEvents(flags & ~WaitForMoreEvents)) {
if (start.elapsed() > maxTime) if (deadline.hasExpired())
break; break;
} }
} }

View File

@ -5,6 +5,7 @@
#define QEVENTLOOP_H #define QEVENTLOOP_H
#include <QtCore/qobject.h> #include <QtCore/qobject.h>
#include <QtCore/qdeadlinetimer.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@ -34,6 +35,7 @@ public:
bool processEvents(ProcessEventsFlags flags = AllEvents); bool processEvents(ProcessEventsFlags flags = AllEvents);
void processEvents(ProcessEventsFlags flags, int maximumTime); void processEvents(ProcessEventsFlags flags, int maximumTime);
void processEvents(ProcessEventsFlags flags, QDeadlineTimer deadline);
int exec(ProcessEventsFlags flags = AllEvents); int exec(ProcessEventsFlags flags = AllEvents);
bool isRunning() const; bool isRunning() const;