Results 1 to 2 of 2

Thread: QAbstractItemModel reset() method

  1. #1
    Join Date
    Sep 2010
    Posts
    62
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QAbstractItemModel reset() method

    Hello,

    In the QAbstractItemModel Class Reference in the description of the reset() method one can read:

    "Use beginResetModel() and endResetModel() instead whenever possible. Use this method only if there is no way to call beginResetModel() before invalidating the model. Otherwise it could lead to unexpected behaviour, especially when used with proxy models."

    does it mean, that e.g. deleting some rows from the model I shall do it like this:
    ...
    beginResetModel();
    beginRemoveRows(parent, fromIdx, toIdx);
    // removing rows
    endRemoveRows();
    endResetModel();
    ...

    instead of calling:

    ...
    beginRemoveRows(parent, fromIdx, toIdx);
    // removing rows
    endRemoveRows();
    reset();
    ...

    thanks

  2. #2
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QAbstractItemModel reset() method

    Why are you trying to reset the model after removing rows? beginRemoveRows() and endRemoveRows() makes sure that the views connected refresh and show appropriately. reset() invalidates model and causes it re-fetch everything.
    You reset when your underlying datastructure has changed or something similar.

Similar Threads

  1. Calling a method from a non-member method
    By AndresBarbaRoja in forum Newbie
    Replies: 5
    Last Post: 19th March 2011, 10:38
  2. Replies: 1
    Last Post: 25th November 2010, 11:37
  3. reset method in QAbstractTableModel
    By TorAn in forum Qt Programming
    Replies: 1
    Last Post: 2nd August 2010, 05:06
  4. QAbstractItemModel reset Persistent Index
    By larcho in forum Qt Programming
    Replies: 8
    Last Post: 5th April 2010, 05:01
  5. Replies: 1
    Last Post: 9th February 2010, 12:11

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.