Search code examples
repeaterqml

How can I create an alias to a property within a Repeater?


This code:

Repeater {
    id: myImageArr
    property alias changeSource: imageElement
    model: 3
    Image {
        id: imageElement
    }
}

gives me an error:

Invalid alias reference. Unable to find id "imageElement"


Solution

  • The Image inside the repeater is dynamically created depending on the model, so you can't refer it directly by id. If your model is a fixed value (3), then you can access the Image instance by using Repeater.itemAt(index) function. For example, to create alias to the first Image created by repeater:

    property alias changeSource: myImageArr.itemAt(0)