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

二次信任 提交于 2019-12-12 18:29:08

问题


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"


回答1:


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)


来源:https://stackoverflow.com/questions/14345552/how-can-i-create-an-alias-to-a-property-within-a-repeater

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!