Qt-interest Archive, September 2007
How to clear a tree model
Message 1 in thread
I have implemented a tree model (class TreeModel) with tree items (class TreeItem).
I want to clear the content of the model. I try this code:
beginRemoveRows(index(0, 0), 0, rootItem->childCount());
while(rootItem->childCount() > 0)
rootItem->removeChild(0);
endRemoveRows();
where rootItem is an istance of class TreeItem. The method removeChild(int) works because if I remove an element in the middle of the tree, I don't have problems.
But if I use this code for clear the tree, I have a read access violation, but not during the erasing, but after, perhaps when the tree must be repainted.
What's the correct way to clear a tree model?
------------------------------------------------------
Leggi GRATIS le tue mail con il telefonino i-mode? di Wind
http://i-mode.wind.it/
--
[ signature omitted ]
Message 2 in thread
On Tuesday 04 September 2007 09:47:01 fabiodago@xxxxxxxxx wrote:
> I have implemented a tree model (class TreeModel) with tree items (class
> TreeItem).
>
> I want to clear the content of the model. I try this code:
>
> beginRemoveRows(index(0, 0), 0, rootItem->childCount());
The parent is incorrect, try this:
beginRemoveRows(QModelIndex(), 0, rootItem->childCount()-1 );
-Benjamin Meyer
--
[ signature omitted ]
Message 3 in thread
On tirsdag den 4. September 2007, fabiodago@xxxxxxxxx wrote:
> I have implemented a tree model (class TreeModel) with tree items (class
> TreeItem).
>
> I want to clear the content of the model. I try this code:
>
> beginRemoveRows(index(0, 0), 0, rootItem->childCount());
> while(rootItem->childCount() > 0)
> rootItem->removeChild(0);
> endRemoveRows();
>
> where rootItem is an istance of class TreeItem. The method removeChild(int)
> works because if I remove an element in the middle of the tree, I don't
> have problems.
>
> But if I use this code for clear the tree, I have a read access violation,
> but not during the erasing, but after, perhaps when the tree must be
> repainted.
>
> What's the correct way to clear a tree model?
When you clear everything, I'd just call reset();
clearStuff();
reset();
Bo.
--
[ signature omitted ]