Results 1 to 2 of 2

Thread: layoutChanged()

  1. #1
    Join Date
    Feb 2007
    Location
    Philadelphia, USA
    Posts
    255
    Thanks
    43
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question layoutChanged()

    I've subclassed QAbstractItemModel. Internally I remove some rows from the model, so I use
    Qt Code:
    1. emit layoutAboutToBeChanged();
    2. ... delete my rows ...
    3. emit layoutChanged();
    To copy to clipboard, switch view to plain text mode 

    Everything works fine, except sometimes where apparently the QTreeView tries to access one of the internal pointers I have already deleted - then I get a seg fault. I know this is the issue because if I remove the rows but don't delete the internal data, then everything is fine (except for a memory leak of course). It doesn't happen all the time... only when I have recently selected a child of the row I am to delete.

    So my question is.... what do I need to do to notify the QTreeView that rows have been removed and internal data has been deleted.

    Thanks

  2. #2
    Join Date
    Feb 2007
    Location
    Philadelphia, USA
    Posts
    255
    Thanks
    43
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: layoutChanged()

    Based on a hint in Qt docs, I solved the problem... when data is deleted you apparently must clear the associated persistent indexes using

    Qt Code:
    1. changePersistentIndex(index,QModelIndex()).
    To copy to clipboard, switch view to plain text mode 

    So, is this true then whenever you delete data in your QAbstractItemModel, you also need to manually clear the persistent indexes?
    Last edited by magland; 20th June 2007 at 18:45.

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.