Qt QML:连接的启用的属性的确切含义是什么

Qt QML: What's the exact meaning of the property of enabled of Connections

我目前在 VS2015 上使用 Qt 5.8.0 64 位,Windows 10 64 位。根据文档,自 5.7.0 以来,类型 Connections 获得了一个新的 属性 作为 enabled。文档说:

This property holds whether the item accepts change events.

我想这个 属性 控制连接是否有效,对吧?但是,当我关闭此 属性 时,连接仍然有效!演示代码如下:

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!");
        }
    }
}

"button Clicked!" 仍然是 运行 从调试输出中出来! 属性 "enabled" 的确切含义是什么?

P.S.: 结果如果我把"enabled"设为true(默认值也是true),关掉Component.onCompleted,连接无效,单击按钮时调试控制台将不再打印 "button Clicked!":

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;
}

这是一个错误吗?

是的,您偶然发现了一个错误,enabled 属性 的初始值被忽略了。 enabled 仅在 Connections 项完全初始化后更改值时才会考虑。因此,您的 Component.onCompleted 技巧是一个很好的解决方法。

我已经在 https://codereview.qt-project.org/#/c/194840/ 解决了这个问题。