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. [Solved]Find a Child in a QTreeView

[Solved]Find a Child in a QTreeView

Scheduled Pinned Locked Moved General and Desktop
16 Posts 4 Posters 22.5k 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.
  • G Offline
    G Offline
    gronerth
    wrote on last edited by
    #5

    is QHash quicker?


    JETG

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #6

      As it seems that you use a "QStandardItemModel":http://doc.qt.nokia.com/4.7/qstandarditemmodel.html, have you tried "QStandardItemModel::findItems() ":http://doc.qt.nokia.com/4.7/qstandarditemmodel.html#findItems already?

      If you need more control you can call "QAbstractItemModel::match() ":http://doc.qt.nokia.com/4.7/qabstractitemmodel.html#match. The latter returns only a QModelIndexList, you will have to peek the items with "QStandardItemModel::itemFromIndex() ":http://doc.qt.nokia.com/4.7/qstandarditemmodel.html#itemFromIndex then.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • G Offline
        G Offline
        gronerth
        wrote on last edited by
        #7

        Hi volker,

        Well i have tried with findItems (and match), but the standarditemmodel only has the root items not the childs....I had to iterate just as Gerolf says...


        JETG

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          ZapB
          wrote on last edited by
          #8

          [quote author="gronerth" date="1301602957"]is QHash quicker?[/quote]
          Possibly but it does not store the items in an ordered manner which is sometimes useful to have if you need to iterate over them in some specific order. Depends upon the exact use case you wish to cater for.

          Nokia Certified Qt Specialist
          Interested in hearing about Qt related work

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #9

            [quote author="gronerth" date="1301605423"]Hi volker,

            Well i have tried with findItems (and match), but the standarditemmodel only has the root items not the childs....I had to iterate just as Gerolf says...[/quote]

            How do you create a hierarchy then? And what model do you use?

            You can add Qt::MatchRecursive to the search flags of match and findItems.

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • G Offline
              G Offline
              gronerth
              wrote on last edited by
              #10

              Well the item root:

              @
              QStandardItem *root = new QStandardItem("rootItem");
              model->setItem(0,root);
              @

              The childs items
              @
              root->setChild(row,device2Add);
              @

              I haven't trie with Qt::MatchRecursive, does it search too in the childs of each item?


              JETG

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #11

                Yes, MatchRecursive makes the search look into the childs too.

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  gronerth
                  wrote on last edited by
                  #12

                  Ok, i didn't know, thanks for the advice..


                  JETG

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on last edited by
                    #13

                    No problem, you're welcome - and that's what this forum is meant for :-)

                    Just let us know, if it works out for your case.

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      gronerth
                      wrote on last edited by
                      #14

                      yep, it works! thanks again...


                      JETG

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        goetz
                        wrote on last edited by
                        #15

                        Again, you're welcome. You can mark the post as solved now: Just hit the edit link of the original post in this thread (it's located under your avatar right of the post) and prepend "[Solved]" to the title.

                        http://www.catb.org/~esr/faqs/smart-questions.html

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          gronerth
                          wrote on last edited by
                          #16

                          done!


                          JETG

                          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