Binding QML Connections to 'enabled' property causes either a warning or an error
-
When I try to set
onEnabledChanged
inConnections
, it shows a warning that I don't think it should be: QML Connections: Implicitly defined onFoo properties in Connections are deprecated. Use this syntax instead: function onFoo(<arguments>) { ... }
Example code of the warning:import QtQuick import QtQuick.Window Window { id: control visible: true width: 640 height: 480 Item { id: item } Connections { target: item enabled: control.visible // any condition onEnabledChanged: console.log("whatever") } }
How to avoid this warning?
-
@Bob64 You misunderstood my point, I want to set
onEnabledChanged
forConnections.enabled
. However, I also found a solution, it might be weird but work well.Connections { target: item enabled: { if (enabled) console.log("enabled is true") else console.log("enabled is false) return control.visible // any condition } }
I'm not pretty sure about it whether has problems.
@Kamichanw Another solution would be to bind to the property outside of Connections and add a property change signal handler there:
Connections { id: connections target: item enabled: control.visible // any condition } readonly property bool connectionsEnabled: connections.enabled onConnectionsEnabledChanged: print("connections enabled", connectionsEnabled)
-
When I try to set
onEnabledChanged
inConnections
, it shows a warning that I don't think it should be: QML Connections: Implicitly defined onFoo properties in Connections are deprecated. Use this syntax instead: function onFoo(<arguments>) { ... }
Example code of the warning:import QtQuick import QtQuick.Window Window { id: control visible: true width: 640 height: 480 Item { id: item } Connections { target: item enabled: control.visible // any condition onEnabledChanged: console.log("whatever") } }
How to avoid this warning?
@Kamichanw It's just telling you to use a more modern syntax I believe:
Connections { ... function onEnabledChanged() { console.log("whatever"); } }
-
@Kamichanw It's just telling you to use a more modern syntax I believe:
Connections { ... function onEnabledChanged() { console.log("whatever"); } }
@Bob64 You misunderstood my point, I want to set
onEnabledChanged
forConnections.enabled
. However, I also found a solution, it might be weird but work well.Connections { target: item enabled: { if (enabled) console.log("enabled is true") else console.log("enabled is false) return control.visible // any condition } }
I'm not pretty sure about it whether has problems.
-
@Bob64 You misunderstood my point, I want to set
onEnabledChanged
forConnections.enabled
. However, I also found a solution, it might be weird but work well.Connections { target: item enabled: { if (enabled) console.log("enabled is true") else console.log("enabled is false) return control.visible // any condition } }
I'm not pretty sure about it whether has problems.
@Kamichanw Another solution would be to bind to the property outside of Connections and add a property change signal handler there:
Connections { id: connections target: item enabled: control.visible // any condition } readonly property bool connectionsEnabled: connections.enabled onConnectionsEnabledChanged: print("connections enabled", connectionsEnabled)
-
-
@Kamichanw Another solution would be to bind to the property outside of Connections and add a property change signal handler there:
Connections { id: connections target: item enabled: control.visible // any condition } readonly property bool connectionsEnabled: connections.enabled onConnectionsEnabledChanged: print("connections enabled", connectionsEnabled)