Results 1 to 3 of 3

Thread: How to delete List of child Nodes from QAbstractItemModel

  1. #1
    Join Date
    Jun 2018
    Location
    India
    Posts
    27
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Question How to delete List of child Nodes from QAbstractItemModel

    Hi,

    I have a QTreeView with Custom Read-only Model derived from QAbstractItemModel. (Followed Qt example:SimpleTreeModel).
    During refresh call, I want to clear/delete all the child nodes under the selected parent node index. What should be the best way to achieve this ?

    1. Do i need to call removeRows() on the selected index ? I don't think this will help as the items to be deleted are not coming from the view.

    2. Do i need to loop through the childCount() and delete each ?

    Or any other way to do this ?

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,528
    Thanks
    13
    Thanked 1,575 Times in 1,504 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to delete List of child Nodes from QAbstractItemModel

    Quote Originally Posted by chithara View Post
    I have a QTreeView with Custom Read-only Model derived from QAbstractItemModel. (Followed Qt example:SimpleTreeModel).
    1. Do i need to call removeRows() on the selected index ? I don't think this will help as the items to be deleted are not coming from the view.
    2. Do i need to loop through the childCount() and delete each ?
    If you have a read-only model then you cannot call removeRows() or removeRow(); these public methods modify the model content from outside.

    During refresh call, I want to clear/delete all the child nodes under the selected parent node index. What should be the best way to achieve this ?
    What is being refreshed? If the data underlying your read-only model (i.e. the private data that is being presented) is changing then you need to make matching beginInsertRows()/endInsertRows() or beginRemoveRows()/endRemoverows() calls in your model's code so that views using the model receive appropriate signals.

  3. #3
    Join Date
    Jun 2018
    Location
    India
    Posts
    27
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How to delete List of child Nodes from QAbstractItemModel

    The private data (QList<object>) should get deleted and new QList should get added to the model.
    I am not using beginInsertRows()/endInsertRows() for the first time to load the data to the model. But do i need to use these functions when the model data gets updated ?

Similar Threads

  1. Replies: 1
    Last Post: 17th February 2011, 17:12
  2. Replies: 0
    Last Post: 11th January 2011, 12:31
  3. Having trouble with direct child nodes using QtXml
    By thelackey3326 in forum Qt Programming
    Replies: 2
    Last Post: 16th July 2008, 21:12
  4. Problem inserting child items into a QAbstractItemModel
    By Valheru in forum Qt Programming
    Replies: 5
    Last Post: 14th October 2006, 18:35
  5. delete items from list box
    By vvbkumar in forum Qt Programming
    Replies: 4
    Last Post: 23rd June 2006, 19:08

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.