diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2022-08-12 11:15:48 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2022-08-12 20:32:30 +0200 |
commit | 45cbb1e31efab23294cd1a5e475986bd3ea9bb10 (patch) | |
tree | e080c18cf628dd7d8ec7c98288b5c84e147382c3 /tests/auto/testlib | |
parent | 54bcefb25c8050b8a3ce9e5afb9fd70d9dff5bca (diff) |
Fix DeferredFlag implementation for QTestEventLoop
As discovered in the expanded testing of QTRY_COMPARE() using the same
class, the timer needs a context object and a slot to call.
This amends commit 35ad157d88c7bfcb9b90b01111b0f43dd2e012d9
Pick-to: 6.4 6.3
Task-number: QTBUG-104441
Change-Id: I41fc23de84ce8c7d6608db0005276a2071974494
Reviewed-by: Jason McDonald <macadder1@gmail.com>
Diffstat (limited to 'tests/auto/testlib')
-rw-r--r-- | tests/auto/testlib/selftests/eventloop/tst_eventloop.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/tests/auto/testlib/selftests/eventloop/tst_eventloop.cpp b/tests/auto/testlib/selftests/eventloop/tst_eventloop.cpp index b5e8efce82..202a8b77f1 100644 --- a/tests/auto/testlib/selftests/eventloop/tst_eventloop.cpp +++ b/tests/auto/testlib/selftests/eventloop/tst_eventloop.cpp @@ -18,21 +18,29 @@ private slots: void pass(); }; -class DeferredFlag +class DeferredFlag : public QObject // Can't be const. { + Q_OBJECT bool m_flag; public: + // A boolean that either starts out true or decays to true after 50 ms. + // However, that decay will only happen when the event loop is run. explicit DeferredFlag(bool initial = false) : m_flag(initial) { if (!initial) - QTimer::singleShot(50, [this] { m_flag = true; }); + QTimer::singleShot(50, this, &DeferredFlag::onTimeOut); } explicit operator bool() const { return m_flag; } bool operator!() const { return !m_flag; } - friend bool operator==(DeferredFlag a, DeferredFlag b) { return bool(a) == bool(b); } + friend bool operator==(const DeferredFlag &a, const DeferredFlag &b) + { + return bool(a) == bool(b); + } +public slots: + void onTimeOut() { m_flag = true; } }; -char *toString(DeferredFlag val) +char *toString(const DeferredFlag &val) { return qstrdup(bool(val) ? "DeferredFlag(true)" : "DeferredFlag(false)"); } |