[PyKDE] Delete of QListViewItems
phil at river-bank.demon.co.uk
Sat Nov 11 11:55:29 GMT 2000
Per Gummedal wrote:
> The QT documentation of QListViewItem::takeItem says:
> Removes item from this object's list of children and causes an update
> of the screen display. The item is not deleted.
> You should normally not need to call this function,
> as QListViewItem::~QListViewItem() calls it.
> The normal way to delete an item is delete.
> In PyQt if I use del(item) the item is not removed from the list,
> if i use takeItem(item) it is, but according to the documentation it
> will not be deleted (from memory).
> Is this a bug, or what function should I use to delete items ?
What you have to do is to takeItem(item) and then del(item).
When a QListViewItem is created from Python, responsibility for calling
the C++ dtor is passed to C++ from Python - because the parent QListView
or QListViewItem takes ownership of it. This means that when you
del(item) (and the reference count reaches zero) the Python object
disappears but the C++ dtor is not called.
Calling takeItem(item) removes the item from the parent QListView or
QListViewItem and transfers reponsibility from calling the C++ dtor back
to Python. This means that when you del(item) (and the reference count
reaches zero) the C++ dtor is called and the item disappears from
I've updated the documentation.
More information about the PyQt