SignalProbe Item¶
-
class
SignalProbe
¶ Watches signals from other items.
Inherits: | Component |
---|---|
Properties: | condition , count , signal |
Methods: | clear() , connect() |
Signals: | triggered() |
Detailed Description¶
SignalProbe
can be used to watch signals of other items. A typical use-case
is a counter for asynchronous events:
import qst 1.0
import QtQml 2.0 as QtQml
Testcase {
QtQml.Timer {
id : timer
interval: 5
periodic: true
}
SignalProbe {
id: probe
signal: timer.triggered
}
function run() {
Qst.compare(probe.count, 0, "Timer triggered too early");
timer.start();
Qst.wait(50);
timer.stop();
Qst.verify(probe.count >= 10, "Timer triggered only "
+ probe.count + " times");
}
The following example shows, how SignalProbe
can be used, to attach to a
signal that is not directly accessible:
import qst 1.0
Testcase {
property var pinProbe : PinProbe {
// properties
// ...
// Can attach directly to the valueChanged() signal.
onValueChanged: {
Qst.info("pin value is " + pinProbe.value)
}
}
}
import qst 1.0
BaseTestcase {
// Cannot attach directly to pinProbe's valueChanged() signal.
// Use SignalProbe instead.
SignalProbe {
signal: pinProbe.valueChanged
onTriggered: {
Qst.info("pin value is " + pinProbe.value)
}
}
}
Properties¶
-
bool
condition
¶ Default: true A guard for
signal
. Whentrue
, incoming signals increment the counter and emittriggered()
. Whenfalse
, the incoming signal is ignored.
-
Signal
signal
¶ A signal of another item to attach to during the creation stage.
Methods¶
-
void
connect
(signalHandler)¶ Connects the
triggered()
signal to a signalHandler of another item. This makesSignalProbe
look like a QML signal for the other item.Example:
DurationConstraint { from: SignalProbe { signal: someItem.someSignal } to: someOtherSignal }
In this example,
DurationConstraint
tries to connectSignalProbe
to itself by callingconnect()
. It doesn’t know thatSignalProbe
is an item and not a plain QML signal.