Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [SOLVED] StackView: check what the currentItem is?
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] StackView: check what the currentItem is?

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 6.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Etchelon
    wrote on last edited by
    #1

    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)
    stack.push(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?

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      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)
                  mystack.push({item:login,properties:{objectName:"login"}});
              }else{
                  console.log("It is not login page")
              }
              var it = mystack.currentItem
              console.log("ObjectName="+it.objectName)
          }@
      

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • E Offline
        E Offline
        Etchelon
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved