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?
Forum Updated to NodeBB v4.3 + New Features

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 1.1k 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.
  • B Offline
    B Offline
    bogong
    wrote on 6 Oct 2019, 15:45 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?

    O 1 Reply Last reply 6 Oct 2019, 16:27
    0
    • B bogong
      6 Oct 2019, 15:45

      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?

      O Offline
      O Offline
      ODБOï
      wrote on 6 Oct 2019, 16:27 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
      • C Offline
        C Offline
        CKurdu
        wrote on 6 Oct 2019, 17:06 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 6 Oct 2019, 17:49
        1
        • C CKurdu
          6 Oct 2019, 17:06

          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 6 Oct 2019, 17:49 last edited by bogong 10 Jun 2019, 18:06
          #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
          • C Offline
            C Offline
            CKurdu
            wrote on 6 Oct 2019, 18:57 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 6 Oct 2019, 20:43
            2
            • C CKurdu
              6 Oct 2019, 18:57

              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 6 Oct 2019, 20:43 last edited by bogong 10 Jun 2019, 20:43
              #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

              1/6

              6 Oct 2019, 15:45

              • Login

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