Results 1 to 3 of 3

Thread: How to remove all rows and chiled rows from QTreeview

  1. #1
    Join Date
    May 2009
    Posts
    83

    Default How to remove all rows and chiled rows from QTreeview

    Hi
    i dont know why im get into trouble with removing all rows and sub rows from qtreeview
    im using QStandardItemModel as the model . now here is my code that doesn't work .


    Qt Code:
    1. QModelIndex FirstQModelIndex;
    2. QModelIndex parentQModelIndex;
    3. int iMdlChidCound = m_model->hasChildren();
    4. if(iMdlChidCound > 0)
    5. {
    6. // only if there at list 1 row in the view
    7. FirstQModelIndex = m_model->item(0,0)->index();
    8. QStandardItem* feedItem = m_model->itemFromIndex(FirstQModelIndex);
    9. // get the parent of the first row its the header row
    10. QStandardItem* parentItem = feedItem->parent();
    11.  
    12.  
    13. // here im getting exception
    14. int parent_rows= parentItem->hasChildren();
    15. parentQModelIndex = m_model->indexFromItem(parentItem);
    16.  
    17.  
    18. // now i like to delete all the rows under the header , and its dosnt work
    19. if(parent_rows>0)
    20. {
    21. bool b = feedItem->model()->removeRows(0,y,parentQModelIndex);
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to remove all rows and chiled rows from QTreeview

    You don't bother to check that "parentItem" is non-NULL, so of course it will throw if parentItem == 0.

  3. #3
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: How to remove all rows and chiled rows from QTreeview

    Quote Originally Posted by umen View Post
    . . . removing all rows and sub rows from qtreeview . . .
    Why not do this?
    Qt Code:
    1. m_model->removeRows(0, m_model->rowCount());
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Remove selected rows from a QTableView
    By niko in forum Qt Programming
    Replies: 4
    Last Post: 3rd March 2016, 13:49
  2. Fetching rows in QtreeView
    By visor_ua in forum Qt Programming
    Replies: 2
    Last Post: 5th July 2008, 19:17
  3. QTreeView rows editable
    By Pesho in forum Qt Programming
    Replies: 5
    Last Post: 13th September 2007, 14:19
  4. Replies: 5
    Last Post: 2nd April 2007, 09:57
  5. [Qt 4.x] Highliting rows in a QTreeView
    By Moppel in forum Qt Programming
    Replies: 3
    Last Post: 10th March 2006, 11:00

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.