Connections QML 类型

Enables connecting a QML signal to a handler. 更多...

导入语句: import QtQuick .
Since: Qt Quick Ultralite 1.0

特性

详细描述

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
        onClicked: { foo(parameters) }
    }
}
						

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

MouseArea {
    id: area
}
// ...
						
Connections {
    target: area
    onClicked: { foo(parameters) }
}
						

特性文档编制

target : Object

此特性保持发送信号的对象。

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