Results 1 to 2 of 2

Thread: Use QIterator on TreeView's model

  1. #1
    Join Date
    Nov 2009
    Posts
    43
    Thanks
    8
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Use QIterator on TreeView's model

    What is the best way to define and use a QIterator on a QTreeView model? I want to iterate through all the items in a QTreeView's model, and I'm having some trouble figuring out the best way to turn a custom model based on QAbstractItemModel into a QListView in order to create the iterator. I'm using an example based more/less on SimpleTreeView in the QT Examples. Thanks in advance for your help.

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

    Default Re: Use QIterator on TreeView's model

    You don't turn a model into the view. The view's data is held in the model so if you want to iterate the items of the view, you just access the model.

    Qt Code:
    1. for(int i = 0; i< tree->model()->rowCount(); i++){
    2. QModelIndex index = tree->index(i, 0); // column no 0
    3. doSomething(index);
    4. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. hierarchical model in a flat view
    By gniking in forum Qt Programming
    Replies: 4
    Last Post: 10th November 2009, 21:17
  2. One Model, Two Views (QTreeView and QTableView)
    By dgarrett97 in forum Newbie
    Replies: 2
    Last Post: 14th September 2009, 19:10
  3. Replies: 2
    Last Post: 24th July 2009, 23:09
  4. Replies: 1
    Last Post: 3rd June 2009, 20:08
  5. Custom Model Advice Requested
    By mclark in forum Qt Programming
    Replies: 3
    Last Post: 18th September 2008, 17:26

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.