QCoreApplication: port processEvents() to QDeadlineTimer
As Eddy pointed out in review, the existing overload API docs says using this method is discouraged; but adding a QDeadlineTimer overload is more about preventing overflow, as it can handle qint64 or chrono::milliseconds. So it's either add this new overload or change the existing one to take a qint64. [ChangeLog][QtCore][QCoreApplication] Added processEvents() overload that takes a QDeadlineTimer. Task-number: QTBUG-110059 Change-Id: I02f938ee8243c09e493bd88ed496b862d87910f7 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
parent
16a19a4f4a
commit
72d660843b
@ -35,7 +35,6 @@
|
||||
#include <private/qthreadpool_p.h>
|
||||
#endif
|
||||
#endif
|
||||
#include <qelapsedtimer.h>
|
||||
#include <qlibraryinfo.h>
|
||||
#include <qvarlengtharray.h>
|
||||
#include <private/qfactoryloader_p.h>
|
||||
@ -1349,12 +1348,29 @@ void QCoreApplication::processEvents(QEventLoop::ProcessEventsFlags flags)
|
||||
}
|
||||
|
||||
/*!
|
||||
\overload processEvents()
|
||||
\overload
|
||||
|
||||
Processes pending events for the calling thread for \a ms
|
||||
milliseconds or until there are no more events to process,
|
||||
whichever is shorter.
|
||||
|
||||
This is equivalent to calling:
|
||||
\code
|
||||
QCoreApplication::processEvents(flags, QDeadlineTimer(ms));
|
||||
\endcode
|
||||
*/
|
||||
void QCoreApplication::processEvents(QEventLoop::ProcessEventsFlags flags, int ms)
|
||||
{
|
||||
QCoreApplication::processEvents(flags, QDeadlineTimer(ms));
|
||||
}
|
||||
|
||||
/*!
|
||||
\since 6.7
|
||||
\overload
|
||||
|
||||
Processes pending events for the calling thread untile \a deadline has expired,
|
||||
or until there are no more events to process, whichever happens first.
|
||||
|
||||
Use of this function is discouraged. Instead, prefer to move long
|
||||
operations out of the GUI thread into an auxiliary one and to completely
|
||||
avoid nested event loop processing. If event processing is really
|
||||
@ -1372,7 +1388,7 @@ void QCoreApplication::processEvents(QEventLoop::ProcessEventsFlags flags)
|
||||
|
||||
\sa exec(), QTimer, QEventLoop::processEvents()
|
||||
*/
|
||||
void QCoreApplication::processEvents(QEventLoop::ProcessEventsFlags flags, int ms)
|
||||
void QCoreApplication::processEvents(QEventLoop::ProcessEventsFlags flags, QDeadlineTimer deadline)
|
||||
{
|
||||
// ### TODO: consider splitting this method into a public and a private
|
||||
// one, so that a user-invoked processEvents can be detected
|
||||
@ -1380,10 +1396,9 @@ void QCoreApplication::processEvents(QEventLoop::ProcessEventsFlags flags, int m
|
||||
QThreadData *data = QThreadData::current();
|
||||
if (!data->hasEventDispatcher())
|
||||
return;
|
||||
QElapsedTimer start;
|
||||
start.start();
|
||||
|
||||
while (data->eventDispatcher.loadRelaxed()->processEvents(flags & ~QEventLoop::WaitForMoreEvents)) {
|
||||
if (start.elapsed() > ms)
|
||||
if (deadline.hasExpired())
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <QtCore/qstring.h>
|
||||
#ifndef QT_NO_QOBJECT
|
||||
#include <QtCore/qcoreevent.h>
|
||||
#include <QtCore/qdeadlinetimer.h>
|
||||
#include <QtCore/qeventloop.h>
|
||||
#include <QtCore/qobject.h>
|
||||
#else
|
||||
@ -93,6 +94,7 @@ public:
|
||||
static int exec();
|
||||
static void processEvents(QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents);
|
||||
static void processEvents(QEventLoop::ProcessEventsFlags flags, int maxtime);
|
||||
static void processEvents(QEventLoop::ProcessEventsFlags flags, QDeadlineTimer deadline);
|
||||
|
||||
static bool sendEvent(QObject *receiver, QEvent *event);
|
||||
static void postEvent(QObject *receiver, QEvent *event, int priority = Qt::NormalEventPriority);
|
||||
|
Loading…
Reference in New Issue
Block a user