Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get list of all items in QML StackView that pushed into stack?

How to get list of all items in QML StackView that pushed into stack?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 973 Views
  • 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.
  • B Offline
    B Offline
    bogong
    wrote on last edited by
    #1

    Hello!
    I am trying to find something about getting list of all items in QML StackView that pushed into stack. Is there any option to get it?

    ODБOïO 1 Reply Last reply
    0
    • B bogong

      Hello!
      I am trying to find something about getting list of all items in QML StackView that pushed into stack. Is there any option to get it?

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      @bogong hi use methodes https://doc.qt.io/qt-5/qml-qtquick-controls2-stackview.html#methods

      1 Reply Last reply
      0
      • CKurduC Offline
        CKurduC Offline
        CKurdu
        wrote on last edited by
        #3

        You can use this function to list all items.

        function listItems(){
        
                    for(var i=0; i<stackView.children.length;i++)
                    {
                        var item = stackView.get(i);
                        console.log(item.title);
                    }
            }
        

        You reap what you sow it

        B 1 Reply Last reply
        1
        • CKurduC CKurdu

          You can use this function to list all items.

          function listItems(){
          
                      for(var i=0; i<stackView.children.length;i++)
                      {
                          var item = stackView.get(i);
                          console.log(item.title);
                      }
              }
          
          B Offline
          B Offline
          bogong
          wrote on last edited by bogong
          #4

          @CKurdu Thx a lot ... Maybe you know how to avoid correctly creating duplicated object in stack? Is there in-box solution? For example if the page "settings" already existed and I don't want to create it again in stack but showing already existed. Is there kind of "singleton" for elements in the stack? Or killing existed in stack when leaving it?

          1 Reply Last reply
          0
          • CKurduC Offline
            CKurduC Offline
            CKurdu
            wrote on last edited by
            #5

            I don't know in-box solution but you can solve your problem with the javascript file. First implement a javascript file like below

            var dict = {};
            var sv;
            function setStackView(item)
            {
                sv = item;
            }
            function push(id,item) {
                if(!dict.hasOwnProperty(id))
                {
                    dict[id] = item;
                    sv.push(item);
                }else{
                    console.debug("dublicate!");
                }
            }
            function get(id)
            {
                return dict[id];
            }
            
            function list()
            {
                console.debug("list");
                var keys = Object.keys(dict);
                for(var i=0; i<keys.length; i++)
                {
                    console.debug(keys[i]+ " : " + dict[keys[i]]);
                }
            }
            

            then you can import and use

            import "StackController.js" as StackController
            ...
            ...
               Component.onCompleted: {
                                StackController.setStackView(stackView);
                                StackController.push("page2",page2)
                                StackController.push("page1",page2)
                                StackController.push("page1",page1)
                                StackController.list();
                }
            
            
            

            But this code only works for item base not for the URL base.

            You reap what you sow it

            B 1 Reply Last reply
            2
            • CKurduC CKurdu

              I don't know in-box solution but you can solve your problem with the javascript file. First implement a javascript file like below

              var dict = {};
              var sv;
              function setStackView(item)
              {
                  sv = item;
              }
              function push(id,item) {
                  if(!dict.hasOwnProperty(id))
                  {
                      dict[id] = item;
                      sv.push(item);
                  }else{
                      console.debug("dublicate!");
                  }
              }
              function get(id)
              {
                  return dict[id];
              }
              
              function list()
              {
                  console.debug("list");
                  var keys = Object.keys(dict);
                  for(var i=0; i<keys.length; i++)
                  {
                      console.debug(keys[i]+ " : " + dict[keys[i]]);
                  }
              }
              

              then you can import and use

              import "StackController.js" as StackController
              ...
              ...
                 Component.onCompleted: {
                                  StackController.setStackView(stackView);
                                  StackController.push("page2",page2)
                                  StackController.push("page1",page2)
                                  StackController.push("page1",page1)
                                  StackController.list();
                  }
              
              
              

              But this code only works for item base not for the URL base.

              B Offline
              B Offline
              bogong
              wrote on last edited by bogong
              #6

              @CKurdu Thx for reply. I am doing similar usually. I've been seeking something that in-box from pure QT without additional storing info about what in stack. Looks like nothing in it yet. First time I've been questioning about it about 4-5 years ago ...

              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