diff options
author | Ahmad Samir <a.samirh78@gmail.com> | 2023-02-15 13:00:27 +0200 |
---|---|---|
committer | Ahmad Samir <a.samirh78@gmail.com> | 2023-03-03 21:36:55 +0200 |
commit | 6f9ace56856bf49d55f96db8610451c65106bed3 (patch) | |
tree | f78b2f6d35ed9e519c75840cf780d025105c4195 /src | |
parent | 2a495c25961d73353339e165d4a4edbce91d7d2c (diff) |
QSignalSpy: add wait(std::chrono::milliseconds) overload
Make the wait(int) overload call the new one.
Task-number: QTBUG-110059
Fixes: QTBUG-100041
Change-Id: Ia085453c05e09e219ba56010b2504113bbc1dd34
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/testlib/qsignalspy.h | 7 | ||||
-rw-r--r-- | src/testlib/qsignalspy.qdoc | 32 |
2 files changed, 31 insertions, 8 deletions
diff --git a/src/testlib/qsignalspy.h b/src/testlib/qsignalspy.h index 7bcaf3c3b3..b72c3b4b53 100644 --- a/src/testlib/qsignalspy.h +++ b/src/testlib/qsignalspy.h @@ -94,12 +94,15 @@ public: inline bool isValid() const { return !sig.isEmpty(); } inline QByteArray signal() const { return sig; } - bool wait(int timeout = 5000) + bool wait(int timeout) + { return wait(std::chrono::milliseconds{timeout}); } + + bool wait(std::chrono::milliseconds timeout = std::chrono::seconds{5}) { Q_ASSERT(!m_waiting); const qsizetype origCount = size(); m_waiting = true; - m_loop.enterLoop(std::chrono::milliseconds{timeout}); + m_loop.enterLoop(timeout); m_waiting = false; return size() > origCount; } diff --git a/src/testlib/qsignalspy.qdoc b/src/testlib/qsignalspy.qdoc index 85b91589f7..e9c213f781 100644 --- a/src/testlib/qsignalspy.qdoc +++ b/src/testlib/qsignalspy.qdoc @@ -110,15 +110,35 @@ \internal */ -/*! \fn QSignalSpy::wait(int timeout) - +/*! \fn bool QSignalSpy::wait(int timeout) \since 5.0 - Starts an event loop that runs until the given signal is received. - Optionally the event loop can return earlier on a \a timeout (in milliseconds). + This is an overloaded function, equivalent passing \a timeout to the + chrono overload: + \code + wait(std::chrono::milliseconds{timeout}); + \endcode + + Returns \c true if the signal was emitted at least once in \a timeout, + otherwise returns \c false. +*/ + +/*! \fn bool QSignalSpy::wait(std::chrono::milliseconds timeout) + \since 6.6 + + Starts an event loop that runs until the given signal is received + or \a timeout has passed, whichever happens first. + + \a timeout is any valid std::chrono::duration (std::chrono::seconds, + std::chrono::milliseconds ...etc). - Returns \c true if the signal was emitted at least once in \a timeout milliseconds, otherwise returns \c false. + Returns \c true if the signal was emitted at least once in \a timeout, + otherwise returns \c false. Example: - \snippet code/doc_src_qsignalspy.cpp 5 + \code + using namespace std::chrono_literals; + QSignalSpy spy(object, signal); + spy.wait(2s); + \endcode */ |