I have a QStandardItemModel that I am using in a QTreeView. It has several levels, and I want to allow the user to expand/contract a specific level. Some of the levels are siblings, I want to allow the user to expand one sibling, but not another. I store the 'name' of the level in Qt::UserRole+1. When the QTreeView displays, a QComboBox with the names gets populated, along with defaults of Expand All and Expand None. I have a signal/slot triggered by changing the Expand Level in the combo box. Expand All and Expand None work fine. I am using the code below:
Qt Code:
  1. void RWPreview::changeExpand( QString level )
  2. {
  3. QModelIndexList idx_list;
  4. if( level.compare( "All") == 0 )
  5. rpt_view-> expandAll();
  6.  
  7. else if( level.compare("None") == 0 )
  8. rpt_view-> collapseAll();
  9.  
  10. else
  11. {
  12. QModelIndex st_idx = ((QStandardItemModel*)rpt_view->model() )->index(0,0);
  13. idx_list = rpt_view->model()->match(st_idx, Qt::UserRole+1, qVariantFromValue(level), -1, Qt::MatchRecursive );
  14. QListIterator<QModelIndex> i( idx_list );
  15. while (i.hasNext())
  16. rpt_view->expand( i.next() );
  17.  
  18. }
  19.  
  20. }
To copy to clipboard, switch view to plain text mode 
I get the expected number of model indexes for the expected rows in the QModelIndexList. It completes the while loop, and exits the if statement. However, when it exits the function, I get an exception. Does anyone have an idea what I can try? If I dont' create the QModelIndexList, it works fine (but obviously, doesn't expand nodes). I'm puzzled!