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

"TypeError: Cannot read property 'x' of undefined" when binding to delegate index and model role in the same binding

    XMLWordPrintable

Details

    Description

      In the attached example, binding to index causes a TypeError when removing the first item from the model. I'm assuming this is because it causes the binding to reevaluate while the model data is changing, but I don't believe this should cause issues. If this is expected behaviour, it should be documented.

      Steps to reproduce:

      1. Run the attached example
      2. Click the button
      main.qml
      import QtQuick 2.0
      import QtQuick.Controls 2.0
      
      import Isle 1.0
      
      ApplicationWindow {
          width: 640
          height: 480
          title: qsTr("Hello World")
          visible: true
      
          Flow {
              Repeater {
                  id: pathRepeater
                  model: PathModel {
                      id: pathModel
                  }
                  delegate: Label {
                      // Works fine
      //                text: model.tilePos.toString()
                      // TypeError: Cannot read property 'x' of undefined
                      // Works if you comment out "index" in the last expression in parentheses.
                      text: "(" + model.tilePos.x + ", " + model.tilePos.y + ")" + (index < pathRepeater.count - 1 ? " " : "")
                  }
              }
          }
      
          Button {
              text: "Remove first path node"
              anchors.bottom: parent.bottom
      
              onClicked: pathModel.removeFirst()
          }
      }
      

      Making "index" and "model" required properties doesn't make a difference:

          required property int index
          required property var model
      

      Making tilePos a required property is a workaround, however:

          text: "(" + tilePos.x + ", " + tilePos.y + ")" + (index < pathRepeater.count - 1 ? " " : "")
          
          required property int index
          required property point tilePos
      

      Attachments

        Issue Links

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

          Activity

            People

              qtqmlteam Qt Qml Team User
              mitch_curtis Mitch Curtis
              Votes:
              1 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes