QtQuick.Controls 2 StackView和destroyOnPop [英] QtQuick.Controls 2 StackView and destroyOnPop

查看:146
本文介绍了QtQuick.Controls 2 StackView和destroyOnPop的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用StackView并将大量动态创建的对象推入此StackView的应用程序,当它们从StackView中弹出时,我需要一些方法来销毁此objecst.如果使用Controls 1 Stackview,则可以仅使用destroyOnPop属性推送对象(如

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})

,但不适用于Controls 2 StackView.这个问题的正确解决方法是什么?

but it doesn't applicable to Controls 2 StackView. What is correct solution of this problem?

我只知道一种方法:弹出对象时,请延迟调用object.destroy(),但是这种方法看起来像kludge.如果重要的话,我可以将任何代码添加到动态生成的对象中

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

推荐答案

控件2 StackView具有简化的所有权语义. StackView拥有其已动态实例化的任何项目的所有权.如果创建了实例,那么您就可以控制实例.换句话说,如果您想破坏StackView,请按下Component或URL,然后让StackView创建实例.

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()

这篇关于QtQuick.Controls 2 StackView和destroyOnPop的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆