Connections QML类型

Connections QML Type

Connections QML类型

Describes generalized connections to signals. More...

描述与信号的通用连接。

Import Statement:import QtQml

Properties

属性

Detailed Description

详细描述

A Connections object creates a connection to a QML signal.

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:

当连接到QML中的信号时,通常的方法是创建一个“on<Signal>”处理器,当接收到信号时,该处理器会做出反应,如下所示:

​MouseArea { onClicked: (mouse)=> { foo(mouse) } }

However, it is not possible to connect to a signal in this way in some cases, such as when:

但是,在某些情况下,不可能以这种方式连接到信号,例如:

  • Multiple connections to the same signal are required
  • 同一信号需要多个连接
  • Creating connections outside the scope of the signal sender
  • 在信号发送器范围之外创建连接
  • Connecting to targets not defined in QML
  • 连接到未定义的QML中的目标

When any of these are needed, the Connections type can be used instead.

当需要其中任何一种连接时,可以使用Connections类型。

For example, the above code can be changed to use a Connections object, like this:

例如,可以将上述代码更改为使用Connections对象,如下所示:

​
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:

更一般地说,Connections对象可以是信号发送方以外的某个对象的子对象:

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

​

See also Qt QML.

​另请参见Qt QML。

Property Documentation

属性文档

[since 5.7]enabled : bool

This property holds whether the item accepts change events.

此属性保存项目是否接受更改事件。

By default, this property is true.

默认情况下,此属性为true。

This property was introduced in Qt 5.7.

Qt 5.7中引入了这个属性。

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.

如果此属性设置为true,则会忽略此类错误。如果要连接到不同类型的对象,并为每个对象处理不同的信号集,这将非常有用。

target : QtObject

This property holds the object that sends the signal.

此属性保存发送信号的对象。

If this property is not set, the target defaults to the parent of the Connection.

如果未设置此属性,则目标默认为连接的父级。

If set to null, no connection is made and any signal handlers are ignored until the target is not null.

如果设置为null,则不进行连接,并且忽略任何信号处理程序,直到目标不为null。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值