Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-84746

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

    XMLWordPrintable

Details

    Description

      Porting my application to Qt 5.15.0 causes a runtime warning when using QML Connections, stating:

      Implicitly defined onFoo properties in Connections are deprecated. Use this syntax instead: function onFoo(<arguments>)\{ ... }
      

      After making the suggested change it works fine for most properties, except for `enabled`, a built-in property, which causes the following error:

      Duplicate method name: invalid override of property change signal or superclass signal
      

      Hereby an example of the warning, the error, and the workaround I use for now.

      Example code of the warning:

      import QtQuick 2.15
      import QtQuick.Window 2.15
      
      Window {
          visible: true
          width: 640
          height: 480
          title: qsTr("This file causes a warning")    
      
          Item {
              id: item
              enabled: true
          }    
      
          Connections {
              target: item
              onEnabledChanged: console.log("whatever")
          }
      }
      
      // This file causes a warning:
      //
      // qrc:/main.qml:15:5: QML Connections: Implicitly defined onFoo properties in Connections are deprecated. Use this syntax instead: function onFoo(<arguments>) { ... }

      Example code of the error after fixing the warning in the suggested way:

      import QtQuick 2.15
      import QtQuick.Window 2.15
      
      Window {
          visible: true
          width: 640
          height: 480
          title: qsTr("This file causes an error")
      
          Item {
              id: item
              enabled: true
          }
      
          Connections {
              target: item
              function onEnabledChanged() {
                  console.log("whatever")
              }
          }
      }
      
      // This file causes a runtime error:
      //
      // QQmlApplicationEngine failed to load component
      // qrc:/main.qml:17:18: Duplicate method name: invalid override of property change signal or superclass signal
      

      Example code of workaround:

      import QtQuick 2.15
      import QtQuick.Window 2.15
      
      Window {
          visible: true
          width: 640
          height: 480
          title: qsTr("This file works fine")
      
          Item {
              id: item
              enabled: true
      //        property alias enabled2: enabled // Causes an error: qrc:/main-workaround.qml:13:34: Invalid alias reference. Unable to find id "enabled"
              property bool enabled2: enabled // works fine
          }
      
          Connections {
              target: item
              function onEnabled2Changed() {
                  console.log("whatever")
              }
          }
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            jdubb Jan Willem Silfhout
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes