Results 1 to 2 of 2

Thread: Hot to get a QModelIndexList from a model?

  1. #1
    Join Date
    Oct 2008
    Location
    Budapest, Hungary
    Posts
    11
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Hot to get a QModelIndexList from a model?

    I would like to get a QModelIndexList from a QStandartItemModel object. Latter is a table and I need the indices of its first columns of all (not only the selected!) rows. I may use QAbstractItemModel::match method, but is not there a more efficient way to get all indices of a model object?

    For the time being I use this awkward way to get it:

    Qt Code:
    1. QModelIndexList indices;
    2. for (int i=0; i<model->rowCount(); i++){
    3. indices << model->indexFromItem(model->item(i, 0));
    4. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Hot to get a QModelIndexList from a model?

    Qt Code:
    1. for(int i=0;i<model->rowCount();i++){
    2. QModelIndex index = model->index(i,0);
    3. }
    To copy to clipboard, switch view to plain text mode 

    You can use the index inside the for loop or add it to a list of indices and use the list afterwards. Just remember not to store it anywhere for later use.

Similar Threads

  1. hierarchical model in a flat view
    By gniking in forum Qt Programming
    Replies: 4
    Last Post: 10th November 2009, 20:17
  2. Coin3d + Qt: SIGLNALs and SLOTs
    By vonCZ in forum Newbie
    Replies: 26
    Last Post: 15th May 2009, 07:34
  3. Model / Threading Advice
    By tntcoda in forum Qt Programming
    Replies: 6
    Last Post: 19th November 2008, 14:02
  4. Custom Model Advice Requested
    By mclark in forum Qt Programming
    Replies: 3
    Last Post: 18th September 2008, 16:26
  5. Model Choices review/questions
    By ucntcme in forum Qt Programming
    Replies: 1
    Last Post: 16th September 2007, 21:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.