Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qeventspy.h
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QEVENTSPY_H
5#define QEVENTSPY_H
6
7#include <QtTest/qttestglobal.h>
8#include <QtCore/qcoreevent.h>
9#include <QtCore/qlist.h>
10
11#include <functional>
12#include <memory>
13
14QT_BEGIN_NAMESPACE
15
16class QObject;
17class QEventSpyPrivate;
18
20{
21public:
22 using Filter = std::function<bool(QObject *receiver, const QEvent *event)>;
23
29
30 Q_TESTLIB_EXPORT bool isValid() const noexcept;
31 Q_TESTLIB_EXPORT QObject *object() const;
32
33 Q_TESTLIB_EXPORT qsizetype count() const noexcept;
35 qsizetype size() const noexcept { return count(); }
36 bool isEmpty() const noexcept { return count() == 0; }
37 bool contains(QEvent::Type type) const noexcept { return count(type) > 0; }
38
40 Q_TESTLIB_EXPORT const QEvent *at(qsizetype i) const;
41 template <typename EventType>
42 const EventType *at(qsizetype i) const
43 { return static_cast<const EventType *>(at(i)); }
45
47
48private:
50
51 std::unique_ptr<QEventSpyPrivate> d_ptr;
52};
53
54QT_END_NAMESPACE
55
56#endif // QEVENTSPY_H
\inmodule QtTest
Definition qeventspy.h:20
bool isEmpty() const noexcept
Returns true if the spy has not recorded any events, otherwise false.
Definition qeventspy.h:36
std::function< bool(QObject *receiver, const QEvent *event)> Filter
A synonym for {std::function<bool(QObject *receiver, const QEvent *event)>}.
Definition qeventspy.h:22
const EventType * at(qsizetype i) const
Definition qeventspy.h:42
bool contains(QEvent::Type type) const noexcept
Returns true if the spy has recorded at least one event of the given type, otherwise false.
Definition qeventspy.h:37
qsizetype size() const noexcept
Same as count().
Definition qeventspy.h:35
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 void clear()
Removes all recorded events from the spy.