StackView: storing components along with their items

落爺英雄遲暮 提交于 2019-12-07 09:14:27
synacker
  1. Create an array of your components, such as here:

    StackView {
       id: stackView
    }
    
    property variant myObjects: [component1.createObject(), component2.createObject(), component3.createObject()] 
    
    Component {
       id: component1
    }
    
    Component {
       id: component2
    }
    
    Component {
       id: component3
    }
    
  2. Then when pushing to StackView make sure to use destroyOnPop property:

    stackView.push({item: myObjects[componentIndex], destroyOnPop: false})
    

By following these two steps, StackView does not take ownership by your objects. Therefore, you can work with objects directly and still push/pop many times to StackView.

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