2016-11-15 47 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