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

Binding evaluates value even !when

XMLWordPrintable

    • 3bb72d31fc18b031bc823d80fec91ee3351d25a2

      Running the code below results in "TypeError: Cannot read property 'color' of null", because apparently the Binding tries to evaluate the value property even though the "when" statement evaluates to false.

      To fix this, one could replace the "when" statement with the alternative "value" statement commented out below, but the current behavior seems wrong.

      import QtQuick 2.0
      
      Rectangle {
          id: root
          width: 300
          height: 400
      
          Binding {
              target: root
              property: "color"
              value: loader.item.color
      //        value: loader.item ? loader.item.color : "white"
              when: Qt.isQtObject(loader.item)
          }
      
          Loader {
              id: loader
              anchors.centerIn: parent
          }
      
          MouseArea {
              anchors.fill: parent
              onClicked: loader.sourceComponent = rect
          }
      
          Component {
              id: rect
              Rectangle {
                  width: 100
                  height: 100
                  color: "blue"
                  border.color: "yellow"
                  border.width: 5
              }
          }
      }
      

        For Gerrit Dashboard: QTBUG-22005
        # Subject Branch Project Status CR V

            ulherman Ulf Hermann
            mathiasm Mathias Malmqvist
            Votes:
            17 Vote for this issue
            Watchers:
            22 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes