To receive a notification when a particular signal is emitted for a particular object, the object definition should declare a signal handler named on<Signal> where <Signal> is the name of the signal, with the first letter capitalized. The signal handler should contain the JavaScript code to be executed when the signal handler is invoked.
QML types have predefined signals that are emitted when users interact with the application. For example, the
Mouse Area
type has a
clicked
signal that is emitted whenever the mouse is clicked within the area. Since the signal name is
clicked
, the signal handler for receiving this signal is named
onClicked
.
A signal is automatically emitted when the value of a QML property changes. This type of signal is a
property change signal
and signal handlers for these signals are written in the form
on<Property>Changed
, where
<Property>
is the name of the property, with the first letter capitalized.
For example, the Mouse Area type has a
pressed
property. To receive a notification whenever this property changes, you would use a signal handler called
onPressedChanged
.
For more information about signals and signal handlers, see 信号和处理程序事件系统 .
To access a signal outside of the object that emits it, you can use the Connections type for connecting to signals of arbitrary objects. A connections object can receive any signal from its specified target. You can connect objects to signals that are available to them in the Connections view.
To connect objects to signals:
(
Add
) button to add a connection.
Right-click a connection and select Open Connection Editor in the context menu to specify the connection in Connection Editor .
If a signal handler that you need is not listed in the Signal Handler column, you can add it:
The added signal handler is automatically exported as a property .