Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
|
\inmodule QtTest More...
#include <qsignalspy.h>
Friends | |
class | QSignalSpyPrivate |
Additional Inherited Members | |
Public Types inherited from QList< QList< QVariant > > | |
using | Type |
using | value_type |
using | pointer |
using | const_pointer |
using | reference |
using | const_reference |
using | size_type |
using | difference_type |
using | parameter_type |
using | rvalue_ref |
using | Iterator |
using | ConstIterator |
using | reverse_iterator |
using | const_reverse_iterator |
Static Public Member Functions inherited from QList< QList< QVariant > > | |
static qsizetype | max_size () noexcept |
static QList< QList< QVariant > > | fromList (const QList< QList< QVariant > > &list) noexcept |
static QList< QList< QVariant > > | fromVector (const QList< QList< QVariant > > &vector) noexcept |
static QList< QList< QVariant > > | fromReadOnlyData (const QList< QVariant >(&t)[N]) noexcept |
Protected Types inherited from QListSpecialMethodsBase< T > | |
using | Self = QList<T> |
Protected Member Functions inherited from QListSpecialMethods< T > | |
~QListSpecialMethods ()=default | |
Protected Member Functions inherited from QListSpecialMethodsBase< T > | |
~QListSpecialMethodsBase ()=default | |
Self * | self () |
const Self * | self () const |
\inmodule QtTest
The QSignalSpy class enables introspection of signal emission.
QSignalSpy can connect to any signal of any object and records its emission. QSignalSpy itself is a list of QVariant lists. Each emission of the signal will append one item to the list, containing the arguments of the signal.
The following example records all signal emissions for the clicked()
signal of a QCheckBox:
{spy.takeFirst()} returns the arguments for the first emitted signal, as a list of QVariant objects. The
clicked()
signal has a single bool argument, which is stored as the first entry in the list of arguments.
The example below catches a signal from a custom object:
To retrieve the instance, you can use qvariant_cast:
Definition at line 21 of file qsignalspy.h.
|
inlineexplicit |
Constructs a new QSignalSpy that listens for emissions of the signal from the QObject object.
If QSignalSpy is not able to listen for a valid signal (for example, because object is \nullptr or signal does not denote a valid signal of object), an explanatory warning message will be output using qWarning() and subsequent calls to isValid()
will return false.
Example:
Definition at line 30 of file qsignalspy.h.
|
inline |
Definition at line 37 of file qsignalspy.h.
|
inline |
Constructs a new QSignalSpy that listens for emissions of the signal from the QObject obj. If QSignalSpy is not able to listen for a valid signal (for example, because obj is \nullptr or signal does not denote a valid signal of obj), an explanatory warning message will be output using qWarning() and subsequent calls to isValid()
will return false.
This constructor is convenient to use when Qt's meta-object system is heavily used in a test.
Basic usage example:
Imagine we need to check whether all properties of the QWindow class that represent minimum and maximum dimensions are properly writable. The following example demonstrates one of the approaches:
Definition at line 40 of file qsignalspy.h.
|
default |
Destructor.
|
inline |
Returns true
if the signal spy listens to a valid signal, otherwise false.
Definition at line 44 of file qsignalspy.h.
References QByteArray::isEmpty().
Referenced by QQuickControlsTestUtils::clickButton(), and QQuickControlsTestUtils::doubleClickButton().
|
inline |
Returns the normalized signal the spy is currently listening to.
Definition at line 45 of file qsignalspy.h.
|
inline |
This is an overloaded function, equivalent passing timeout to the chrono overload:
Returns true
if the signal was emitted at least once in timeout, otherwise returns false
.
Definition at line 47 of file qsignalspy.h.
References wait().
Referenced by wait().
bool QSignalSpy::wait | ( | std::chrono::milliseconds | timeout = std::chrono::seconds{5} | ) |
Starts an event loop that runs until the given signal is received or timeout has passed, whichever happens first.
timeout is any valid std::chrono::duration (std::chrono::seconds, std::chrono::milliseconds ...etc).
Returns true
if the signal was emitted at least once in timeout, otherwise returns false
.
Example:
Definition at line 145 of file qsignalspy.cpp.
References QTestEventLoop::enterLoop(), Q_ASSERT, QMutexLocker< Mutex >::relock(), QList< QList< QVariant > >::size(), and QMutexLocker< Mutex >::unlock().
|
friend |
Definition at line 27 of file qsignalspy.h.