Call function when StackView.pop
-
Hi.
If you make "stackview.push", "Component.onCompleted" will work, but if you do "stackview.pop" then the second time it is not called.
I need to call the function of the current "Item" when I do "stackview.pop". I can not find the signal I need.property int testNum: 1 StackView { id: stack anchors.fill: parent initialItem: view1 onCurrentItemChanged: { // I think I need to write something here, but what? } } Component { id: view1 Rectangle { color: "lightblue" // I need to call this function after stack.pop function func() { testNum *= 10 } // Component.on ??? // This is called only once Component.onCompleted: func() Text { text: testNum.toString() anchors.centerIn: parent } MouseArea { anchors.fill: parent onClicked: stack.push(view2) } } } Component { id: view2 Rectangle { color: "lightgreen" MouseArea { anchors.fill: parent onClicked: { testNum++ stack.pop() } } } }
-
The counterpart for
Component::onCompleted()
isComponent::onDestruction()
. -
my Pages all have a name property
property string name: "QueueItemDetailPage"
I do not simply a pop() on the stack, I'm calling popOnePage()
function popOnePage() { var page = pop() if(page.name == "QueueItemDetailPage") { // if using Loader deactivate here or call functions if not using onDeconstruction() page.mySpecialFunction() detailLoader.active = false return } // and also for the next ones } // popOnePage
take a look at some of my sample apps where I'm doing this
https://appbus.wordpress.com/category/qt-for-mobile/overview/ -
Depending on what you're trying to achieve, some of the attached signals introduced in Qt Quick Controls 2.1 in Qt 5.8 might be useful:
StackView::activating()
StackView::activated()
StackView::desctivating()
StackView::deactivated()
StackView::removed()
For your particular use case, the last one might be interesting.
Component { id: view2 Rectangle { StackView.onRemoved: doSomething() } }
-
@jpnurmi
thx.
have overlooked these new signals from 2.1 -
Many thanks to all!
I forgot to say that I use Qt 5.7. If it is necessary.
I don't understand why I didn't get it right away :)property int testNum: 1 StackView { id: stack anchors.fill: parent initialItem: view1 function ff() { // if (depth or name ...) {} currentItem.func() } } Component { id: view1 Rectangle { color: "lightblue" function func() { testNum *= 10 } Component.onCompleted: func() Text { text: testNum.toString() anchors.centerIn: parent } MouseArea { anchors.fill: parent onClicked: stack.push(view2) } } } Component { id: view2 Rectangle { color: "lightgreen" MouseArea { anchors.fill: parent onClicked: { testNum++ stack.pop() // Additionally call the function stack.ff() } } } }
jpnurmi, in the future I will go to Qt 5.8
ekkescorner, a wonderful blog, I will definitely read it.