![]() |
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 <qeventspy.h>
Public Types | |
| using | Filter = std::function<bool(QObject *receiver, const QEvent *event)> |
A synonym for {std::function<bool(QObject *receiver, const QEvent *event)>}. | |
Public Member Functions | |
| Q_TESTLIB_EXPORT | QEventSpy (QObject *objectobject) |
| Constructs a QEventSpy that records all events delivered to object. | |
| Q_TESTLIB_EXPORT | QEventSpy (QObject *objectobject, QEvent::Type typetype) |
| Constructs a QEventSpy that records events of the given type delivered to object. | |
| Q_TESTLIB_EXPORT | QEventSpy (QObject *objectobject, const QList< QEvent::Type > &typestypes) |
| Constructs a QEventSpy that records events of the given types delivered to object. | |
| Q_TESTLIB_EXPORT | QEventSpy (QObject *objectobject, Filter filterfilter) |
Constructs a QEventSpy that records the events delivered to object for which filter returns true. | |
| Q_TESTLIB_EXPORT | ~QEventSpy () |
| Destroys the QEventSpy, and removes it as an event filter from the spied-on object. | |
| Q_TESTLIB_EXPORT bool | isValid () const noexcept |
Returns true if the spy was constructed with a valid object, otherwise false. | |
| Q_TESTLIB_EXPORT QObject * | object () const |
| Returns the object the spy was installed on, or \nullptr if the object has been destroyed. | |
| Q_TESTLIB_EXPORT qsizetype | count () const noexcept |
| Returns the number of recorded events. | |
| Q_TESTLIB_EXPORT qsizetype | count (QEvent::Type typetype) const noexcept |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the number of recorded events of the given type. | |
| qsizetype | size () const noexcept |
| Same as count(). | |
| bool | isEmpty () const noexcept |
Returns true if the spy has not recorded any events, otherwise false. | |
| bool | contains (QEvent::Type typetype) const noexcept |
Returns true if the spy has recorded at least one event of the given type, otherwise false. | |
| Q_TESTLIB_EXPORT QList< QEvent::Type > | eventList () const |
| Returns the types of the recorded events, in the order the spy saw them, including repeated types. | |
| Q_TESTLIB_EXPORT const QEvent * | at (qsizetype i) const |
| Returns a copy of the recorded event at index position i. | |
| template<typename EventType> | |
| const EventType * | at (qsizetype i) const |
| Q_TESTLIB_EXPORT QObject * | receiver (qsizetype i) const |
| Returns the object that the event at index position i was delivered to. | |
| Q_TESTLIB_EXPORT void | clear () |
| Removes all recorded events from the spy. | |
\inmodule QtTest
The QEventSpy class enables introspection of event delivery.
QEventSpy installs itself as an event filter on a QObject and records the events delivered to it, in the order they arrive. QEventSpy never filters out or modifies the events it observes.
The following example verifies that showing a widget delivers a single \l{QEvent::}{Show} event to it:
To record several event types, or all events, pass a list of types, or an empty list:
For more fine-grained control, pass a QEventSpy::Filter. This is useful when spying on the application object, which sees the events of all objects:
QEventSpy stores a copy of each recorded event, made with QEvent::clone() at the time the event filter sees it. The copy can be inspected using at():
Event types that do not reimplement QEvent::clone() are recorded as a plain QEvent of the same type.
To wait for events that are delivered asynchronously, use one of the QTRY_ macros, or QTest::qWaitFor(), with a condition that states what the test is waiting for:
QEventSpy must be created in the thread of the object it spies on.
Definition at line 19 of file qeventspy.h.
| using QEventSpy::Filter = std::function<bool(QObject *receiver, const QEvent *event)> |
A synonym for {std::function<bool(QObject *receiver, const QEvent *event)>}.
A filter returns true for each event that the spy should record.
Definition at line 22 of file qeventspy.h.
|
explicit |
Constructs a QEventSpy that records all events delivered to object.
If object is \nullptr, a warning is output using qWarning() and subsequent calls to isValid() return false.
Definition at line 135 of file qeventspy.cpp.
| QEventSpy::QEventSpy | ( | QObject * | object, |
| QEvent::Type | type ) |
Constructs a QEventSpy that records events of the given type delivered to object.
If object is \nullptr, a warning is output using qWarning() and subsequent calls to isValid() return false.
Definition at line 147 of file qeventspy.cpp.
| QEventSpy::QEventSpy | ( | QObject * | object, |
| const QList< QEvent::Type > & | types ) |
Constructs a QEventSpy that records events of the given types delivered to object.
If types is empty, all events are recorded.
If object is \nullptr, a warning is output using qWarning() and subsequent calls to isValid() return false.
Definition at line 161 of file qeventspy.cpp.
Constructs a QEventSpy that records the events delivered to object for which filter returns true.
If filter is empty, all events are recorded.
If object is \nullptr, a warning is output using qWarning() and subsequent calls to isValid() return false.
Definition at line 176 of file qeventspy.cpp.
|
default |
Destroys the QEventSpy, and removes it as an event filter from the spied-on object.
Definition at line 42 of file qeventspy.h.
Returns a copy of the recorded event at index position i.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Returns a copy of the recorded event at index position i, cast to EventType.
i must be a valid index position (0 <= i < count()). The returned pointer is valid until the event is removed from the spy, or the spy is destroyed.
The caller must ensure that the event is of type EventType, for example by checking QEvent::type().
Definition at line 271 of file qeventspy.cpp.
| void QEventSpy::clear | ( | ) |
Removes all recorded events from the spy.
Definition at line 304 of file qeventspy.cpp.
|
inlinenoexcept |
Returns true if the spy has recorded at least one event of the given type, otherwise false.
Definition at line 37 of file qeventspy.h.
|
noexcept |
Returns the number of recorded events.
Definition at line 223 of file qeventspy.cpp.
|
noexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the number of recorded events of the given type.
Definition at line 233 of file qeventspy.cpp.
| QList< QEvent::Type > QEventSpy::eventList | ( | ) | const |
Returns the types of the recorded events, in the order the spy saw them, including repeated types.
Definition at line 255 of file qeventspy.cpp.
|
inlinenoexcept |
Returns true if the spy has not recorded any events, otherwise false.
Definition at line 36 of file qeventspy.h.
|
noexcept |
Returns true if the spy was constructed with a valid object, otherwise false.
The spy remains valid if the object is later destroyed.
Definition at line 193 of file qeventspy.cpp.
| QObject * QEventSpy::object | ( | ) | const |
Returns the object the spy was installed on, or \nullptr if the object has been destroyed.
Definition at line 202 of file qeventspy.cpp.
Returns the object that the event at index position i was delivered to.
i must be a valid index position (0 <= i < count()). The object may have been destroyed since the event was recorded.
Definition at line 295 of file qeventspy.cpp.
|
inlinenoexcept |
Same as count().
Definition at line 35 of file qeventspy.h.