QtQuick.Controls 2 StackView and destroyOnPop

我们两清 提交于 2019-12-24 00:25:16

问题


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 Components 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

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