Accessing Delegates from Outside the Delegate
-
Hello,
Can we access delegates(ListView) from outside a Delegate Declaration.Say i want to change a property like state of a Delegate.
For eg. in this sample code can i access a particular row delegate of list_view1 ?@
Component{
id:listDelegateItem{ }
}
ListView {
id: list_view1
width:parent.width
height: parent.heightmodel: myModel delegate:listDelegate }
@
-
This is not possible in general since delegates are created on-demand (and thrown away at will when no longer necessary). So the delegate you are requesting may in fact not exist.
So you have to either expose the necessary properties to allow the delegate to react to that, or the delegate can call a method and pass itself as a parameter, then you know you can access the delegate through this parameter.
-
I have a question about this solution:
Suppose the delegate calls a method that put it on a variable (say myDelegate). This variable can be someone else's property or just a javascript variable.
Now, suppose I remove, from the model, the item associated with this delegate instance. Will the instance itself be deleted? Or will it be retained, since there's still a reference to it in myDelegate variable? In other words, the value in myDelegate will then be undefined?