Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Binding QML Connections to 'enabled' property causes either a warning or an error
Forum Update on Monday, May 27th 2025

Binding QML Connections to 'enabled' property causes either a warning or an error

Scheduled Pinned Locked Moved Solved QML and Qt Quick
6 Posts 3 Posters 586 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kamichanw
    wrote on last edited by
    #1

    When I try to set onEnabledChanged in Connections, 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?

    B 1 Reply Last reply
    0
    • K Kamichanw

      @Bob64 You misunderstood my point, I want to set onEnabledChanged for Connections.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.

      GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #5

      @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)
      
      K 1 Reply Last reply
      0
      • K Offline
        K Offline
        Kamichanw
        wrote on last edited by
        #2

        Or, how to connect onEnableChanged in Connections?

        1 Reply Last reply
        0
        • K Kamichanw

          When I try to set onEnabledChanged in Connections, 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?

          B Offline
          B Offline
          Bob64
          wrote on last edited by
          #3

          @Kamichanw It's just telling you to use a more modern syntax I believe:

              Connections {
                  ...
                  function onEnabledChanged() { console.log("whatever"); }
              }
          
          K 1 Reply Last reply
          1
          • B Bob64

            @Kamichanw It's just telling you to use a more modern syntax I believe:

                Connections {
                    ...
                    function onEnabledChanged() { console.log("whatever"); }
                }
            
            K Offline
            K Offline
            Kamichanw
            wrote on last edited by
            #4

            @Bob64 You misunderstood my point, I want to set onEnabledChanged for Connections.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.

            GrecKoG 1 Reply Last reply
            0
            • K Kamichanw

              @Bob64 You misunderstood my point, I want to set onEnabledChanged for Connections.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.

              GrecKoG Offline
              GrecKoG Offline
              GrecKo
              Qt Champions 2018
              wrote on last edited by
              #5

              @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)
              
              K 1 Reply Last reply
              0
              • K Kamichanw has marked this topic as solved on
              • GrecKoG GrecKo

                @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)
                
                K Offline
                K Offline
                Kamichanw
                wrote on last edited by
                #6

                @GrecKo bravo

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved