描述信号的一般化连接。 更多...
import 语句: | import QtQml |
Connections 对象创建到 QML 信号的连接。
When connecting to signals in QML, the usual way is to create an "on<Signal>" handler that reacts when a signal is received, like this:
MouseArea { onClicked: (mouse)=> { foo(mouse) } }
However, it is not possible to connect to a signal in this way in some cases, such as when:
When any of these are needed, the Connections type can be used instead.
For example, the above code can be changed to use a Connections object, like this:
MouseArea { Connections { function onClicked(mouse) { foo(mouse) } } }
More 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) { foo(mouse) } }
注意:
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.
另请参阅 Qt QML .
enabled : bool |
此特性保持项是否接受改变事件。
默认情况下,此特性为
true
.
ignoreUnknownSignals : bool |
Normally, a connection to a non-existent signal produces runtime errors.
If this property is set to
true
, such errors are ignored. This is useful if you intend to connect to different types of objects, handling a different set of signals for each object.
target : QtObject |
此特性保持发送信号的对象。
如果未设置此特性,
target
默认为连接的父级。
If set to null, no connection is made and any signal handlers are ignored until the target is not null.