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

Binding evaluates value even !when

    XMLWordPrintable

Details

    Description

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

      Attachments

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

        Activity

          People

            shausman Simon Hausmann
            mathiasm Mathias Malmqvist
            Votes:
            17 Vote for this issue
            Watchers:
            20 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes