我目前在 VS2015、Windows 10 64 位上使用 Qt 5.8.0 64 位。根据文档,该类型从 5.7.0Connections
开始获得了新属性。enabled
医生说:
此属性保存项目是否接受更改事件。
我猜这个属性控制连接是否有效,对吧?但是,当我关闭此属性时,连接仍在工作!演示代码如下:
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Button{
id: button
anchors.centerIn: parent
width: 100
height: 50
text: "Click!"
}
Connections{
target: button
enabled: false
onClicked:{
console.log("button Clicked!");
}
}
}
“点击按钮!” 仍然从调试输出中耗尽!属性“启用”的确切含义是什么?
PS:事实证明,如果我将“启用”设置为真(默认值也是真),然后将其关闭Component.onCompleted
,连接将变为无效,并且调试控制台不会打印“按钮单击!” 单击按钮时不再:
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Button{
id: button
anchors.centerIn: parent
width: 100
height: 50
text: "Click!"
}
Connections{
id: connections
target: button
enabled: true
onClicked:{
console.log("button Clicked!");
}
}
Component.onCompleted: connections.enabled = false;
}
它是一个错误吗?