C

Connections QML Type

Enables connecting a QML signal to a handler. More...

Import Statement: import QtQuick
Since: Qt Quick Ultralite 1.0

Properties

Detailed Description

A Connections object connects a QML signal to a handler.

Usually, QML signals are connected to an "on<Signal>" handler that reacts to the signal whenever it is triggered. Like in the following example:

MouseArea {
   onClicked: { foo(parameters) }
}

However, it is not possible to use the on<Signal> handler in the following cases:

  • Adding multiple connections to the same signal
  • Creating connections outside the scope of the signal sender
  • Connecting to targets that are not defined in QML

In any of these cases, use the Connections type instead.

For example, the earlier example can be modified to use a Connections object, like this:

MouseArea {
    id: mouseArea
    Connections {
        target: mouseArea
        function onClicked(mouse: MouseEvent) { foo(mouse) }
    }
}

Generally, the Connections object can be a child of some object other than the sender of the signal:

MouseArea {
    id: area
}
// ...
Connections {
    target: area
    function onClicked(mouse: MouseEvent) { foo(mouse) }
}

Note: For backwards compatibility you can also specify the signal handlers without function, like you would specify them directly in the target object. This is not recommended. If you specify one signal handler this way, then all signal handlers specified as function in the same Connections object are ignored.

Property Documentation

target : Object

This property holds the object that sends the signal.

It must be set to the target's id or the singleton object.


Available under certain Qt licenses.
Find out more.