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] to get QStandardItemModel item by key without looping using rowCount()?
Forum Updated to NodeBB v4.3 + New Features

[solved] to get QStandardItemModel item by key without looping using rowCount()?

Scheduled Pinned Locked Moved General and Desktop
13 Posts 4 Posters 16.7k 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
    Edico
    wrote on last edited by
    #2

    QStandardItemModel::findItems()

    1 Reply Last reply
    0
    • U Offline
      U Offline
      umen242
      wrote on last edited by
      #3

      Thanks ! that helped

      1 Reply Last reply
      0
      • U Offline
        U Offline
        umen242
        wrote on last edited by
        #4

        I have Treeview as view , and QStandardItemModel as the model also using QSortFilterProxyModel subclass
        to implement less ten method for sorting .
        Now I have input that automatically updates the treeview . the input comes as structure that contains id's and there data .
        ( each id has 2 or 3 columns of data that needs to be represents as colums in the row ).
        Now . what im doing now is looping thorw all model with rowCount. This could be long loop .
        In this loop im checking each first column Qt::UserRule Data of each row becose this where I store the id.
        Now my question is . how can do something like findItems that finds in UserRule data .?

        1 Reply Last reply
        0
        • EddyE Offline
          EddyE Offline
          Eddy
          wrote on last edited by
          #5

          Eddy : merged the 2 topics because basically they are about the same issue.

          Qt Certified Specialist
          www.edalsolutions.be

          1 Reply Last reply
          0
          • L Offline
            L Offline
            loladiro
            wrote on last edited by
            #6

            Something like this might work:
            @
            QModelIndexList indexes = model->match(model->index(0, 0 /* column /, QModelIndex()),
            Qt::UserRole, id /
            your data /, -1 / find all matches /, flags);
            QList<QStandardItem
            > items;
            for (int i = 0; i < indexes.size(); ++i)
            items.append(model->itemFromIndex(indexes.at(i)));
            return items;

            @
            also have a look at the appropriate "flags":http://doc.qt.nokia.com/4.7/qt.html#MatchFlag-enum

            1 Reply Last reply
            0
            • U Offline
              U Offline
              umen242
              wrote on last edited by
              #7

              what do you think will be faster ? to stay with the model rowCount or go with like your suggestion ?

              1 Reply Last reply
              0
              • L Offline
                L Offline
                loladiro
                wrote on last edited by
                #8

                I don't think there will be much of a difference. However you could try to benchmark the two (use an an average data set for your application, start a timer, and stop it after you used one function 10000 times and then you do the same thing with the other method).

                1 Reply Last reply
                0
                • U Offline
                  U Offline
                  umen242
                  wrote on last edited by
                  #9

                  Hi
                  its working great anther question if i can , how can i get / navigate all the column that in the same row
                  as the item i found ? basically i need to get all items from this row .
                  Thanks allot

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    loladiro
                    wrote on last edited by
                    #10

                    QModelIndex has the sibling() function. I guess that would be the best option, because it's aware of the treeview hierarchy.

                    @
                    QModelIndex index;
                    index.sibling(index.row(),column);
                    @

                    1 Reply Last reply
                    0
                    • U Offline
                      U Offline
                      umen242
                      wrote on last edited by
                      #11

                      Thanks , i guess to get the row index number i can get with item->row() . right?

                      1 Reply Last reply
                      0
                      • U Offline
                        U Offline
                        umen242
                        wrote on last edited by
                        #12

                        Can i ask last question on this thread .
                        if i have item and this item has child nods , how can i remove all the child nods under the selected
                        item ?

                        Thanks Allot

                        1 Reply Last reply
                        0
                        • EddyE Offline
                          EddyE Offline
                          Eddy
                          wrote on last edited by
                          #13

                          Hi Umen,

                          I see that you started a new topic with your last question.
                          If you consider this thread solved can you edit the title and add [solved] ?

                          Thanks

                          Qt Certified Specialist
                          www.edalsolutions.be

                          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