问题
I have application which uses StackView and pushes a lot of dynamic created objects into this StackView and I need some way to destroy this objecst when they are popped from StackView. If I use Controls 1 Stackview, I can just push object with destroyOnPop property (like it was shown in this question):
tablesStack.push({item: view, destroyOnPop: true})
but it doesn't applicable to Controls 2 StackView. What is correct solution of this problem?
I know only one way: call object.destroy() with delay when I pop it, but this way looks like kludge. If it is important, I can add any code to dynamic generated objects
回答1:
Controls 2 StackView
has simplified ownership semantics. StackView
takes ownership of any item that it has dynamically instantiated. If you have created the instance, then you're in control of the instance. In other words, if you want StackView
to destroy, push Component
s or URLs and let StackView
create the instances.
If you need access the created instance, you can simply handle the return value:
var view = stackView.push(component, {"foo": 1, "bar": 2})
view.doSomething()
来源:https://stackoverflow.com/questions/39063235/qtquick-controls-2-stackview-and-destroyonpop