问题
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