[SOLVED] Find item in Stackview that has been pushed onto it as URL

  • Hello,

    is there a possibility to address an item in a stackview that has been pushed onto it as URL? I used the following code:

    @stackView.push( {item: Qt.resolvedUrl("Test.qml")} );@

    In my application, I push a lot of qml-files onto the Stackview with this method. Now I want to unwind the stack to certain positions or find certain items in the stack, but I don't know the item names. The following code does not work:

    @stackView.pop( {item: Qt.resolvedUrl("Test.qml")} );@

    Is there a solution for this? I don't want to work with the index because when my program changes, the index of an item in the stack could also change.

    Thank you.

  • You can search for specific items on a StackView with the find() method.
    For example this should work (not tested):

    @var item = stackView.find(function(item, index) { return item.objectName === "TestPage" })

    Of course you have to set the objectName when you push the item:
    @stackView.push( {item: Qt.resolvedUrl("Test.qml"), properties: { objectName: "TestPage" }} );@

  • Thank you so much! I knew that there is a find() method, but I didn't think of using a property as an identifier...

    I changed my code as you suggested and it works perfectly.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.