diff options
author | Ahmad Samir <[email protected]> | 2024-08-22 22:43:51 +0300 |
---|---|---|
committer | Ahmad Samir <[email protected]> | 2024-08-31 18:57:17 +0300 |
commit | 7d353a5de94bfc628d368262fc4a635a7f845d51 (patch) | |
tree | 457fbbe24e9e188036bd005e732f2e83c0c3c39d | |
parent | 2226581b0b01d57d0d3f6c9433531e3ae3dd5ab1 (diff) |
QTestEventLoop: use QBasicTimer instead of handling raw timer IDs
Change-Id: I427168a37bbb0b3ad2aa0f212a2c089fab68c06f
Reviewed-by: Volker Hilsheimer <[email protected]>
-rw-r--r-- | src/testlib/qtesteventloop.h | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/testlib/qtesteventloop.h b/src/testlib/qtesteventloop.h index 6e908806905..1cef911f68f 100644 --- a/src/testlib/qtesteventloop.h +++ b/src/testlib/qtesteventloop.h @@ -7,6 +7,7 @@ #include <QtTest/qttestglobal.h> #include <QtTest/qtestcase.h> +#include <QtCore/qbasictimer.h> #include <QtCore/qcoreapplication.h> #include <QtCore/qeventloop.h> #include <QtCore/qobject.h> @@ -30,7 +31,7 @@ public: inline void enterLoop(std::chrono::milliseconds msecs); inline void changeInterval(int secs) - { killTimer(timerId); timerId = startTimer(secs * 1000); } + { timer.start(std::chrono::seconds{secs}, this); } inline bool timeout() const { return _timeout; } @@ -51,7 +52,7 @@ protected: private: QEventLoop *loop = nullptr; - int timerId = -1; + QBasicTimer timer; uint _timeout :1; Q_DECL_UNUSED_MEMBER uint reserved :31; }; @@ -67,7 +68,7 @@ inline void QTestEventLoop::enterLoop(std::chrono::milliseconds msecs) using namespace std::chrono_literals; QEventLoop l; // if tests want to measure sub-second precision, use a precise timer - timerId = startTimer(msecs, msecs < 1s ? Qt::PreciseTimer : Qt::CoarseTimer); + timer.start(msecs, msecs < 1s ? Qt::PreciseTimer : Qt::CoarseTimer, this); loop = &l; l.exec(); @@ -82,9 +83,7 @@ inline void QTestEventLoop::exitLoop() return; } - if (timerId != -1) - killTimer(timerId); - timerId = -1; + timer.stop(); if (loop) loop->exit(); @@ -92,7 +91,7 @@ inline void QTestEventLoop::exitLoop() inline void QTestEventLoop::timerEvent(QTimerEvent *e) { - if (e->timerId() != timerId) + if (e->id() != timer.id()) return; _timeout = true; exitLoop(); |