SignalSpy QML Type | Qt Quick Test 5.15.18 (original) (raw)
Enables introspection of signal emission. More...
Import Statement: | import QtTest 1.15 |
---|---|
Since: | Qt 4.8 |
Inherits: | Item |
Properties
- ****count** : int
- ****signalArguments** : list
- ****signalName** : string
- ****target** : var
- ****valid** : bool
Methods
Detailed Description
In the following example, a SignalSpy is installed to watch the "clicked" signal on a user-defined Button type. When the signal is emitted, the count property on the spy will be increased.
Button { id: button SignalSpy { id: spy target: button signalName: "clicked" } TestCase { name: "ButtonClick" function test_click() { compare(spy.count, 0) button.clicked(); compare(spy.count, 1) } } }
The above style of test is suitable for signals that are emitted synchronously. For asynchronous signals, the wait() method can be used to block the test until the signal occurs (or a timeout expires).
See also TestCase and Qt Quick Test.
Property Documentation
[read-only] signalArguments : list
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. When connecting to a new target or new signalName or calling the clear() method, the signalArguments will be reset to empty.
See also signalName and clear().
This property defines the name of the signal on target to listen for.
This property defines the target object that will be used to listen for emissions of the signalName signal.
See also signalName and count.
Method Documentation
Waits for the signal signalName on target to be emitted, for up to timeout milliseconds. The test case will fail if the signal is not emitted.
SignalSpy { id: spy target: button signalName: "clicked" }
function test_async_click() { ... // do something that will cause clicked() to be emitted ... spy.wait() compare(spy.count, 1) }
There are two possible scenarios: the signal has already been emitted when wait() is called, or the signal has not yet been emitted. The wait() function handles the first scenario by immediately returning if the signal has already occurred.
The clear() method can be used to discard information about signals that have already occurred to synchronize wait() with future signal emissions.
See also clear() and TestCase::tryCompare().
© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.