0

I want to unwind till the second last item in StackView. The documentation states it should be as easy as stackView.pop({item: itemName}), but this is working as if I'm doing stackView.pop(). What is the correct way of unwinding till a specific item?

My Qt version is 5.14.2.

Mohammad Ali
  • 117
  • 5

1 Answers1

1

The documentation you linked is the one for QQC1's StackView. For Qt Quick Controls 2 StackView, the pop function is a bit different : https://doc.qt.io/qt-5/qml-qtquick-controls2-stackview.html#pop-method

You can call it like so : stackView.pop(itemName). Note that itemName need to be an instance of the item pushed on the stack. If you push Components on the StackView, trying to pop with a reference to the Component won't work.

// this works :
stackView.push(itemInstance);
...
stackView.pop(itemInstance);

// this doesn't work:
stackView.push(component);
...
stackView.pop(component);

// you could store the instance of the item created from the component like so:
createdItem = stackView.push(component);
...
stackView.pop(createdItem);

// or use StackView.find
const itemToPop = stackView.find(item => return item.objectName === "pop me");
stackView.pop(itemToPop)

// or StackView.get to get an item from its position in the stack:
const itemToPop = stackView.get(1);
stackView.pop(itemToPop);
GrecKo
  • 6,615
  • 19
  • 23
  • I was making the silly mistake of using `Component` instead of `Item`. Thanks for both pointing out how I may have been going wrong and how to go about solving the issue if using components with `StackView`. – Mohammad Ali Sep 09 '21 at 11:58