1/****************************************************************************
2**
3** Copyright (C) 2019 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the documentation of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:FDL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Free Documentation License Usage
18** Alternatively, this file may be used under the terms of the GNU Free
19** Documentation License version 1.3 as published by the Free Software
20** Foundation and appearing in the file included in the packaging of
21** this file. Please review the following information to ensure
22** the GNU Free Documentation License version 1.3 requirements
23** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
24** $QT_END_LICENSE$
25**
26****************************************************************************/
27
28/*!
29 \class QSignalSpy
30 \inmodule QtTest
31
32 \brief The QSignalSpy class enables introspection of signal emission.
33
34 QSignalSpy can connect to any signal of any object and records its emission.
35 QSignalSpy itself is a list of QVariant lists. Each emission of the signal
36 will append one item to the list, containing the arguments of the signal.
37
38 The following example records all signal emissions for the \c clicked() signal
39 of a QCheckBox:
40
41 \snippet code/doc_src_qsignalspy.cpp 0
42
43 \c{spy.takeFirst()} returns the arguments for the first emitted signal, as a
44 list of QVariant objects. The \c clicked() signal has a single bool argument,
45 which is stored as the first entry in the list of arguments.
46
47 The example below catches a signal from a custom object:
48
49 \snippet code/doc_src_qsignalspy.cpp 1
50
51 \note Non-standard data types need to be registered, using
52 the qRegisterMetaType() function, before you can create a
53 QSignalSpy. For example:
54
55 \snippet code/doc_src_qsignalspy.cpp 2
56
57 To retrieve the instance, you can use qvariant_cast:
58
59 \snippet code/doc_src_qsignalspy.cpp 3
60
61 \section1 Verifying Signal Emissions
62
63 The QSignalSpy class provides an elegant mechanism for capturing the list
64 of signals emitted by an object. However, you should verify its validity
65 after construction. The constructor does a number of sanity checks, such as
66 verifying that the signal to be spied upon actually exists. To make the
67 diagnosis of test failures easier, the results of these checks should be
68 checked by calling \c QVERIFY(spy.isValid()) before proceeding further with
69 a test.
70
71 \sa QVERIFY()
72 */
73
74/*! \fn QSignalSpy::QSignalSpy(const QObject *object, const char *signal)
75
76 Constructs a new QSignalSpy that listens for emissions of the \a signal
77 from the QObject \a object. If QSignalSpy is not able to listen for a
78 valid signal (for example, because \a object is \nullptr or \a signal does
79 not denote a valid signal of \a object), an explanatory warning message
80 will be output using qWarning() and subsequent calls to \c isValid() will
81 return false.
82
83 Example:
84 \snippet code/doc_src_qsignalspy.cpp 4
85*/
86
87/*! \fn template <typename PointerToMemberFunction> QSignalSpy::QSignalSpy(const QObject *object, PointerToMemberFunction signal)
88 \since 5.4
89
90 Constructs a new QSignalSpy that listens for emissions of the \a signal
91 from the QObject \a object. If QSignalSpy is not able to listen for a
92 valid signal (for example, because \a object is \nullptr or \a signal does
93 not denote a valid signal of \a object), an explanatory warning message
94 will be output using qWarning() and subsequent calls to \c isValid() will
95 return false.
96
97 Example:
98 \snippet code/doc_src_qsignalspy.cpp 6
99*/
100
101/*! \fn QSignalSpy::QSignalSpy(const QObject *obj, const QMetaMethod &signal)
102 \since 5.14
103
104 Constructs a new QSignalSpy that listens for emissions of the \a signal
105 from the QObject \a obj. If QSignalSpy is not able to listen for a
106 valid signal (for example, because \a obj is \nullptr or \a signal does
107 not denote a valid signal of \a obj), an explanatory warning message
108 will be output using qWarning() and subsequent calls to \c isValid() will
109 return false.
110
111 This constructor is convenient to use when Qt's meta-object system is
112 heavily used in a test.
113
114 Basic usage example:
115 \snippet code/doc_src_qsignalspy.cpp 7
116
117 Imagine we need to check whether all properties of the QWindow class
118 that represent minimum and maximum dimensions are properly writable.
119 The following example demonstrates one of the approaches:
120 \snippet code/doc_src_qsignalspy.cpp 8
121*/
122
123/*! \fn QSignalSpy::isValid() const
124
125 Returns \c true if the signal spy listens to a valid signal, otherwise false.
126*/
127
128/*! \fn QSignalSpy::signal() const
129
130 Returns the normalized signal the spy is currently listening to.
131*/
132
133/*! \fn int QSignalSpy::qt_metacall(QMetaObject::Call call, int id, void **a)
134 \internal
135*/
136
137/*! \fn QSignalSpy::wait(int timeout)
138
139 \since 5.0
140
141 Starts an event loop that runs until the given signal is received.
142 Optionally the event loop can return earlier on a \a timeout (in milliseconds).
143
144 Returns \c true if the signal was emitted at least once in \a timeout milliseconds, otherwise returns \c false.
145
146 Example:
147 \snippet code/doc_src_qsignalspy.cpp 5
148*/
149