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>
This commit is contained in:
Ahmad Samir 2023-02-15 13:00:27 +02:00
parent 2a495c2596
commit 6f9ace5685
2 changed files with 31 additions and 8 deletions

View File

@ -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;
}

View File

@ -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 milliseconds, otherwise returns \c false.
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,
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
*/