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

Required properties do not work with models containing JS objects

XMLWordPrintable

      I have a repeater which uses a list of JS objects as a model.
      I was using modelData.property to access the elements of the JS object before.

      Now I try to switch to using required properties:

      Repeater {
          model: [
              {"inUse": false, "azimuth": 123, "elevation": 35, "identifier": 10},
              {"inUse": true, "azimuth": 278, "elevation": 67, "identifier": 11},
          ]
          delegate: Rectangle {
              required property bool inUse
              required property real azimuth
              required property real elevation
              required property int identifier
      
              width: 30
              height: width
              radius: width / 2
              color: inUse ? root.inUseColor : root.inViewColor
              visible: azimuth > -1 && elevation > -1
              property real angle: (azimuth - 90) / 180 * Math.PI
              property real distance: root.maxCircleRadius * (90 - elevation) / 90
              x: root.centerX + distance * Math.cos(angle) - width / 2
              y: root.centerY + distance * Math.sin(angle) - height / 2
              Text {
                  anchors.centerIn: parent
                  text: identifier
              }
          }
      }

      With this code I get the "Required property <name> was not initialized" error for every property.

      The solution for now is to use

      required property var modelData

      and go back to accessing all the elements using it.

       

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

            qtqmlteam Qt Qml Team User
            ivan.solovev Ivan Solovev
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes