Problems with Open-Source Downloads read and

[SOLVED] StackView: check what the currentItem is?

  • Hi,

    I have a StackView with 2 pages: the initial one and the login page, which is pushed to the StackView when the user wants to login.
    In some cases I want to push the login page to the stack only if it's not already the current item.
    The code is like this
    Component {
    id: mainPage
    MyMainPage { }
    Component {
    id: loginPage
    MyLoginPage { }

    StackView {
    id: stack

    // Something else
    MyEngine {
    onMySignal: {
    if (stack.currentItem !== loginPage)

    Problem: even though the currentItem is the loginPage, it is pushed once again. What exactly does happen when I run the comparison stack.currentItem !== loginPage? I tried to debug and I noticed that currentItem contains properties of the MyLoginPage qml component... so what's the problem?

  • Qt Champions 2017

    You try with following. Don't just insert Item. Have some properties as follows.

    @ mystack.push({item:login,properties:{objectName:"login"}});

            if (mystack.currentItem.objectName != "login" ){
                console.log("Add Login ="+mystack.depth)
                console.log("It is not login page")
            var it = mystack.currentItem

  • Thank you, that works. I also learned that objectName must be a property already declared in the qml file of the page I want to push, it won't be attached at runtime by the push function. Not a problem, since declaring, in each page, a string property with the page name makes perfect sense.

Log in to reply