Search code examples
qmlqt-quick

property location in qml


I have error

ReferenceError: redRow is not defined

on this code:

Repeater {
            property int redRow: 0
            ...
            Image {
                ...
                anchors.bottom: parent.bottom
                anchors.bottomMargin: height / 16 + height * redRow
                ...
            }

if i put
property int redRow: 0

in the begin of file - all right, why i don't have a opportunity put this in Repeater element?


Solution

  • You can put this in the repeater but you have to reference this variable by the id of repeater:

    Repeater {
      id: repeater //add id to the repeater this can be any unique identifier
      property int redRow: 0
      ...
      Image {
        ...
        anchors.bottom: parent.bottom
        anchors.bottomMargin: height / 16 + height * repeater.redRow //reference repeaters property
        ...
      }
    }