Results 1 to 5 of 5

Thread: RemoveRow problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: RemoveRow problem

    May we see the removeRows() implementation of the model? Notice that the second parameter of QAbstractItemModel::removeRow() is parent of item being removed so for a flat model it should be an invalid index.
    J-P Nurmi

  2. #2
    Join Date
    Aug 2007
    Posts
    19
    Qt products
    Qt3 Qt4
    Platforms
    Windows
    Thanks
    5

    Default Re: RemoveRow problem

    there is no removeRows implementation, that is using the the
    Qt Code:
    1. bool QAbstractItemModel::removeRow ( int row, const QModelIndex & parent = QModelIndex() )
    To copy to clipboard, switch view to plain text mode 
    call.

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: RemoveRow problem

    QAbstractItemModel::removeRow() is a convenience function that further calls QAbstractItemModel::removeRows(). QAbstractItemModel::removeRows(), on the other hand, does nothing but returns false. You should provide a proper re-implementation for QAbstractItemModel::removeRows(). This includes calling QAbstractItemModel::beginRemoveRows(), modifying the internal data structure, and then calling QAbstractItemModel::endRemoveRows(). This ensures that the view gets updated correctly.
    J-P Nurmi

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: RemoveRow problem

    This is for example how QStringListModel implements removeRows():
    Qt Code:
    1. bool QStringListModel::removeRows(int row, int count, const QModelIndex &parent)
    2. {
    3. Q_UNUSED(parent);
    4. if (count <= 0 || row < 0 || (row + count) > rowCount(parent))
    5. return false;
    6.  
    7. beginRemoveRows(QModelIndex(), row, row + count - 1);
    8.  
    9. for (int r = 0; r < count; ++r)
    10. lst.removeAt(row);
    11.  
    12. endRemoveRows();
    13.  
    14. return true;
    15. }
    To copy to clipboard, switch view to plain text mode 
    Here "lst" is the internal data structure, a QStringList.
    J-P Nurmi

Similar Threads

  1. Graphics view display problem.
    By kiranraj in forum Qt Programming
    Replies: 3
    Last Post: 20th July 2007, 07:08
  2. [QMYSQL] connection problem
    By chaos_theory in forum Installation and Deployment
    Replies: 5
    Last Post: 2nd July 2007, 09:52
  3. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54
  4. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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
  •  
Qt is a trademark of The Qt Company.