1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the test suite of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
43 \qmlclass SignalSpy SignalSpy
44 \brief Enables introspection of signal emission
45 \ingroup qtquick-utility
49 In the following example, a SignalSpy is installed to watch the
50 "clicked" signal on a user-defined Button element. When the signal
51 is emitted, the \l count property on the spy will be increased.
63 function test_click() {
72 The above style of test is suitable for signals that are emitted
73 synchronously. For asynchronous signals, the wait() method can be
74 used to block the test until the signal occurs (or a timeout expires).
80 \qmlproperty object SignalSpy::target
82 This property defines the target object that will be used to
83 listen for emissions of the \l signalName signal.
89 \qmlproperty string SignalSpy::signalName
91 This property defines the name of the signal on \l target to
98 \qmlproperty list SignalSpy::signalArguments
100 This property holds a list of emitted signal arguments. Each emission of the signal will append one item to the list, containing the arguments of the signal.
101 When connecting to a new \l target or new \l signalName or calling the \l clear() method, the \l signalArguments will be reset to empty.
103 \sa signalName, clear()
108 \qmlproperty bool SignalSpy::valid
110 This property defines the current signal connection status. It will be true when the \l signalName of the \l target is connected successfully, otherwise it will be false.
112 \sa count, target, signalName, clear()
117 \qmlproperty int SignalSpy::count
119 This property defines the number of times that \l signalName has
120 been emitted from \l target since the last call to clear().
122 \sa target, signalName, clear()
127 \qmlmethod SignalSpy::clear()
129 Clears \l count to 0, resets \l valid to false and clears the \l signalArguments to empty.
135 \qmlmethod SignalSpy::wait(timeout = 5000)
137 Waits for the signal \l signalName on \l target to be emitted,
138 for up to \a timeout milliseconds. The test case will fail if
139 the signal is not emitted.
145 signalName: "clicked"
148 function test_async_click() {
150 // do something that will cause clicked() to be emitted
153 compare(spy.count, 1)
157 There are two possible scenarios: the signal has already been
158 emitted when wait() is called, or the signal has not yet been
159 emitted. The wait() function handles the first scenario by immediately
160 returning if the signal has already occurred.
162 The clear() method can be used to discard information about signals
163 that have already occurred to synchronize wait() with future signal
166 \sa clear(), TestCase::tryCompare()