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 ****************************************************************************/
44 \instantiates SignalSpy
45 \brief Enables introspection of signal emission
46 \ingroup qtquick-utility
50 In the following example, a SignalSpy is installed to watch the
51 "clicked" signal on a user-defined Button element. When the signal
52 is emitted, the \l count property on the spy will be increased.
64 function test_click() {
73 The above style of test is suitable for signals that are emitted
74 synchronously. For asynchronous signals, the wait() method can be
75 used to block the test until the signal occurs (or a timeout expires).
81 \qmlproperty object SignalSpy::target
83 This property defines the target object that will be used to
84 listen for emissions of the \l signalName signal.
90 \qmlproperty string SignalSpy::signalName
92 This property defines the name of the signal on \l target to
99 \qmlproperty list SignalSpy::signalArguments
101 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.
102 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.
104 \sa signalName, clear()
109 \qmlproperty bool SignalSpy::valid
111 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.
113 \sa count, target, signalName, clear()
118 \qmlproperty int SignalSpy::count
120 This property defines the number of times that \l signalName has
121 been emitted from \l target since the last call to clear().
123 \sa target, signalName, clear()
128 \qmlmethod SignalSpy::clear()
130 Clears \l count to 0, resets \l valid to false and clears the \l signalArguments to empty.
136 \qmlmethod SignalSpy::wait(timeout = 5000)
138 Waits for the signal \l signalName on \l target to be emitted,
139 for up to \a timeout milliseconds. The test case will fail if
140 the signal is not emitted.
146 signalName: "clicked"
149 function test_async_click() {
151 // do something that will cause clicked() to be emitted
154 compare(spy.count, 1)
158 There are two possible scenarios: the signal has already been
159 emitted when wait() is called, or the signal has not yet been
160 emitted. The wait() function handles the first scenario by immediately
161 returning if the signal has already occurred.
163 The clear() method can be used to discard information about signals
164 that have already occurred to synchronize wait() with future signal
167 \sa clear(), TestCase::tryCompare()