Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
\inmodule QtTest More...
#include <qsignalspy.h>
Public Member Functions | |
QSignalSpy (const QObject *obj, const char *aSignal) | |
Constructs a new QSignalSpy that listens for emissions of the signal from the QObject object. | |
template<typename Func > | |
QSignalSpy (const typename QtPrivate::FunctionPointer< Func >::Object *obj, Func signal0) | |
QSignalSpy (const QObject *obj, QMetaMethod signal) | |
Q_TESTLIB_EXPORT | ~QSignalSpy () |
Destructor. | |
bool | isValid () const noexcept |
Returns true if the signal spy listens to a valid signal, otherwise false. | |
QByteArray | signal () const |
Returns the normalized signal the spy is currently listening to. | |
bool | wait (int timeout) |
Q_TESTLIB_EXPORT bool | wait (std::chrono::milliseconds timeout=std::chrono::seconds{5}) |
Public Member Functions inherited from QList< QList< QVariant > > | |
QList (DataPointer dd) noexcept | |
constexpr | QList () noexcept=default |
QList (qsizetype size) | |
QList (qsizetype size, parameter_type t) | |
QList (std::initializer_list< QList< QVariant > > args) | |
QList (InputIterator i1, InputIterator i2) | |
QList (const String &str) | |
QList (qsizetype size, Qt::Initialization) | |
QList< T > & | operator= (std::initializer_list< QList< QVariant > > args) |
void | swap (QList &other) noexcept |
QTypeTraits::compare_eq_result_container< QList, U > | operator== (const QList &other) const |
QTypeTraits::compare_eq_result_container< QList, U > | operator!= (const QList &other) const |
QTypeTraits::compare_lt_result_container< QList, U > | operator< (const QList &other) const noexcept(noexcept(std::lexicographical_compare< typename QList< U >::const_iterator, typename QList::const_iterator >(std::declval< QList< U > >().begin(), std::declval< QList< U > >().end(), other.begin(), other.end()))) |
QTypeTraits::compare_lt_result_container< QList, U > | operator> (const QList &other) const noexcept(noexcept(other< std::declval< QList< U > >())) |
QTypeTraits::compare_lt_result_container< QList, U > | operator<= (const QList &other) const noexcept(noexcept(other< std::declval< QList< U > >())) |
QTypeTraits::compare_lt_result_container< QList, U > | operator>= (const QList &other) const noexcept(noexcept(std::declval< QList< U > >()< other)) |
qsizetype | size () const noexcept |
qsizetype | count () const noexcept |
qsizetype | count (const AT &t) const noexcept |
qsizetype | length () const noexcept |
bool | isEmpty () const noexcept |
void | resize (qsizetype size) |
void | resize (qsizetype size, parameter_type c) |
void | resizeForOverwrite (qsizetype size) |
qsizetype | capacity () const |
void | reserve (qsizetype size) |
void | squeeze () |
void | detach () |
bool | isDetached () const noexcept |
bool | isSharedWith (const QList< T > &other) const |
pointer | data () |
const_pointer | data () const noexcept |
const_pointer | constData () const noexcept |
void | clear () |
const_reference | at (qsizetype i) const noexcept |
reference | operator[] (qsizetype i) |
const_reference | operator[] (qsizetype i) const noexcept |
void | append (parameter_type t) |
void | append (const_iterator i1, const_iterator i2) |
void | append (rvalue_ref t) |
void | append (const QList< T > &l) |
void | append (QList< T > &&l) |
void | prepend (rvalue_ref t) |
void | prepend (parameter_type t) |
reference | emplaceBack (Args &&... args) |
reference | emplaceFront (Args &&... args) |
iterator | insert (qsizetype i, parameter_type t) |
iterator | insert (qsizetype i, qsizetype n, parameter_type t) |
iterator | insert (const_iterator before, parameter_type t) |
iterator | insert (const_iterator before, qsizetype n, parameter_type t) |
iterator | insert (const_iterator before, rvalue_ref t) |
iterator | insert (qsizetype i, rvalue_ref t) |
QList & | assign (qsizetype n, parameter_type t) |
QList & | assign (InputIterator first, InputIterator last) |
QList & | assign (std::initializer_list< QList< QVariant > > l) |
iterator | emplace (const_iterator before, Args &&... args) |
iterator | emplace (qsizetype i, Args &&... args) |
void | replace (qsizetype i, parameter_type t) |
void | replace (qsizetype i, rvalue_ref t) |
void | remove (qsizetype i, qsizetype n=1) |
void | removeFirst () noexcept |
void | removeLast () noexcept |
value_type | takeFirst () |
value_type | takeLast () |
QList< T > & | fill (parameter_type t, qsizetype size=-1) |
void | removeAt (qsizetype i) |
qsizetype | removeAll (const AT &t) |
bool | removeOne (const AT &t) |
qsizetype | removeIf (Predicate pred) |
QList< QVariant > | takeAt (qsizetype i) |
void | move (qsizetype from, qsizetype to) |
iterator | begin () |
const_iterator | begin () const noexcept |
iterator | end () |
const_iterator | end () const noexcept |
const_iterator | cbegin () const noexcept |
const_iterator | cend () const noexcept |
const_iterator | constBegin () const noexcept |
const_iterator | constEnd () const noexcept |
reverse_iterator | rbegin () |
const_reverse_iterator | rbegin () const noexcept |
reverse_iterator | rend () |
const_reverse_iterator | rend () const noexcept |
const_reverse_iterator | crbegin () const noexcept |
const_reverse_iterator | crend () const noexcept |
iterator | erase (const_iterator begin, const_iterator end) |
iterator | erase (const_iterator pos) |
QList< QVariant > & | first () |
const QList< QVariant > & | first () const noexcept |
QList< T > | first (qsizetype n) const |
const QList< QVariant > & | constFirst () const noexcept |
QList< QVariant > & | last () |
const QList< QVariant > & | last () const noexcept |
QList< T > | last (qsizetype n) const |
const QList< QVariant > & | constLast () const noexcept |
bool | startsWith (parameter_type t) const |
bool | endsWith (parameter_type t) const |
QList< T > | mid (qsizetype pos, qsizetype len=-1) const |
QList< T > | sliced (qsizetype pos) const |
QList< T > | sliced (qsizetype pos, qsizetype n) const |
QList< QVariant > | value (qsizetype i) const |
QList< QVariant > | value (qsizetype i, parameter_type defaultValue) const |
void | swapItemsAt (qsizetype i, qsizetype j) |
void | push_back (parameter_type t) |
void | push_back (rvalue_ref t) |
void | push_front (rvalue_ref t) |
void | push_front (parameter_type t) |
void | pop_back () noexcept |
void | pop_front () noexcept |
reference | emplace_back (Args &&... args) |
bool | empty () const noexcept |
reference | front () |
const_reference | front () const noexcept |
reference | back () |
const_reference | back () const noexcept |
void | shrink_to_fit () |
constexpr qsizetype | max_size () const noexcept |
QList< T > & | operator+= (const QList< T > &l) |
QList< T > & | operator+= (QList< T > &&l) |
QList< T > & | operator+= (parameter_type t) |
QList< T > & | operator+= (rvalue_ref t) |
QList< T > | operator+ (const QList< T > &l) const & |
QList< T > | operator+ (const QList< T > &l) && |
QList< T > | operator+ (QList< T > &&l) const & |
QList< T > | operator+ (QList< T > &&l) && |
QList< T > & | operator<< (parameter_type t) |
QList< T > & | operator<< (const QList< T > &l) |
QList< T > & | operator<< (QList< T > &&l) |
QList< T > & | operator<< (rvalue_ref t) |
QList< T > | toList () const noexcept |
QList< T > | toVector () const noexcept |
Public Member Functions inherited from QListSpecialMethodsBase< QList< QVariant > > | |
qsizetype | indexOf (const AT &t, qsizetype from=0) const noexcept |
qsizetype | lastIndexOf (const AT &t, qsizetype from=-1) const noexcept |
bool | contains (const AT &t) const noexcept |
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 constexpr qsizetype | maxSize () |
static QList< T > | fromList (const QList< T > &list) noexcept |
static QList< T > | fromVector (const QList< T > &vector) noexcept |
static QList< T > | fromReadOnlyData (const QList< QVariant >(&t)[N]) noexcept |
Protected Types inherited from QListSpecialMethodsBase< QList< QVariant > > | |
using | Self |
Protected Member Functions inherited from QListSpecialMethods< QList< QVariant > > | |
~QListSpecialMethods ()=default | |
Protected Member Functions inherited from QListSpecialMethodsBase< QList< QVariant > > | |
~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.
References QSignalSpy().
Referenced by QSignalSpy().
|
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.
|
inlinenoexcept |
Returns true
if the signal spy listens to a valid signal, otherwise false.
Definition at line 44 of file qsignalspy.h.
|
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.
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.
|
friend |
Definition at line 27 of file qsignalspy.h.