2016-11-15 113 views
0

我不确定是否正确使用StackView。 我有几个QML对象,我向他们展示替换StackView中的currentItem。这是一个简单的方法,可以在不使用两个Loaders的情况下进行转换。QML:StackView并替换

喜欢的东西:

import QtQuick 2.5 
import QtQuick.Controls 1.4 

StackView { 
    id: stack 
    anchors.fill: parent 
    initialItem: initObj 
} 

Component { 
    id: initObj 
    ModuleHome {} 
} 

Component { 
    id: obj1 
    Module1 {} 
} 

// ... 

stack.push({item: item, replace: true, destroyOnPop: true}) 

它发生在我一个页面有一个bug,我注意到在调试控制台的错误信息被重复多次,我推的对象。

I.e. 首播时间:

qrc:/MyObject.qml:15: TypeError: Cannot write property of null

二时间:

qrc:/MyObject.qml:15: TypeError: Cannot write property of null

qrc:/MyObject.qml:15: TypeError: Cannot write property of null

第三次:

qrc:/MyObject.qml:15: TypeError: Cannot write property of null

qrc:/MyObject.qml:15: TypeError: Cannot write property of null

qrc:/MyObject.qml:15: TypeError: Cannot write property of null

我想知道如果replace国旗在push方法是确实pop(因此破坏)包含的对象和所有对象。

+0

那么,什么是你的问题?什么是你正在谈论的2'Loader's?什么是“物品”? – folibis

+0

问题是:“我是否正确使用StackView?”,“在推送新对象之前替换实际弹出对象?”。如果要在对象之间进行转换,则需要两个加载器:一个加载当前内容,一个加载新对象,然后它们将交换。项目只是一个占位符来显示代码,它是组件的ID(obj1,等等......) – Mark

+0

哟可能想看看'SwipeView' – derM

回答

1

http://doc.qt.io/qt-5/qml-qtquick-controls-stackview.html

There are three primary navigation operations in StackView: push(), pop(), and replace (replace by specifying argument replace to push()). These correspond to classic stack operations where "push" adds an item to the top of a stack, "pop" removes the top item from the stack, and "replace" is like a pop followed by a push, in that it replaces the topmost item on the stack with a new item

我认为你的问题可能与此有关:

QML StackView: Item Destroyed on pop

(使用项目,而不是组件)

+0

是的,你是对的。在这些日子里,我试图改变我的代码,并在那个线程中解决了。 – Mark