I have a model/view system where I am attempting to implement drag and drop. The actual drag and drop seems to be operating correctly... but the model::removeRows() function doesn't appear to be working as documented.

Here's an example... take the tree describe below

Qt Code:
  1. rootnode
  2. |
  3. |----A
  4. |----B
  5. |----C
To copy to clipboard, switch view to plain text mode 
I can drag C to go under B, but QtGui calls removeRows() with C as the parent, rather than rootnode (invalid QModelIndex).

the relevant code:
Qt Code:
  1. bool modelPlugins::removeRows(int row, int count, const QModelIndex & parent)
  2. {
  3. int index(0);
  4. modelPluginItem * parentItem;
  5. if(row < 0 || row + count > rowCount(parent))
  6. return false;
  7. if(parent.isValid())
  8. parentItem = static_cast<modelPluginItem *>(parent.internalPointer());
  9. else
  10. parentItem = rootItem;
  11. beginRemoveRows(parent, row, row + count - 1);
  12. for(; index < count; index++)
  13. parentItem->nondestructiveremovechild(row);
  14. endRemoveRows();
  15. return true;
  16. }
To copy to clipboard, switch view to plain text mode 
In my debugger, the modelPluginItems each have a unique id... the root node has ID 0, and C has ID 3... parentItem has ID 3. I can see this if Qt were to attempt to remove all children before removing the item, but it never tries to remove row 2 with an invalid parent index. How can I fix this?