Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Removing row from QAbstractItemModel
Forum Updated to NodeBB v4.3 + New Features

Removing row from QAbstractItemModel

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Valerian
    wrote on last edited by
    #1

    Hi all,

    I'm using QML treeview with model sub-classed from QAbstractItemModel.
    I'm facing this issue that model indexes aren't updated when user removes a row.

    Here's the code

        bool TreeModel::removeRows(int row, int count, const QModelIndex &parent)
        {
        	TreeItem *parentItem = getItem(parent);
         
        if(parentItem == null) return false;
         
        	bool success = false;
         
        	if (count > 0)
        	{
        		beginRemoveRows(parent, row, row + count - 1);
        		success = parentItem->removeChildren(row, count);
        		endRemoveRows();
        	}
         
        	return success;
        }
         
        bool TreeItem::removeChildren(int position, int count)
        {
        	if (position < 0 || position + count > children_.size())
        		return false;
         
        	for (int row = 0; row < count; ++row)
        		delete children_.takeAt(position);
         
        	return true;
        }
    

    Could you point what am I missing?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Brembo Breidscheid
      wrote on last edited by
      #2

      Hi,

      I have exactly the same issue. The ony way I could solve it is to call beginResetModel and endResetModel after I deleted the rows.

      It seems to me like a bug in the TreeView / ItemDelegate implementation because this works using a C++ QTreeView.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved