Connecting Objects to Signals
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
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
For more information about signals and signal handlers, see Signal and Handler Event System.
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:
- In the Connections view, select the Connections tab.
- Select the (Add) button to add a connection.
- Double-click the value in the Target column to add the object to connect to a signal.
- Double-click the value in the Signal Handler column to select the signal that the connection will listen to from a list of all signals available for the object.
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:
- Right-click a component in the Navigator or Form Editor view and select Add New Signal Handler in the context menu.
- In the Signal field, select the signal to handle.
- Select the radio buttons to filter the list to only display frequently used signals or property changes.
- Select OK.
The added signal handler is automatically exported as a property.
For more information about the logical operators that you can use to construct conditional expressions, see Summary of Logical Operators.
- Select Action as the type of the connections object.
- Select the object to connect to a signal.
- Select the action to perform when the signal is emitted.
- Select Assignment as the type of the connections object.
- Select the target object for the property assignment.
- Select the property of the target object to assign a value to.
- Select the source object for the property assignment.
- Select the property of the source object to fetch the value from.
Available under certain Qt licenses.
Find out more.