[Kde-bindings] qtruby: ListView::takeItem segfault

Richard Dale Richard_Dale at tipitina.demon.co.uk
Mon Jun 28 16:23:37 UTC 2004


On Monday 28 June 2004 16:29, Hans Fugal wrote:
> listview.takeItem(item) results in a segfault. I'd like to see this
> fixed or figure out another way to remove an item from a ListView. The
> C++ docs say to delete it, this is obviously not the thing to do in ruby
> (or other GC languages).
I've had a look at the docs for takeItem() and it doesn't sound too safe:

"Removes item from this object's list of children and causes an update of the 
screen display. The item is not deleted. You should not normally need to call 
this function because QListViewItem::~QListViewItem() calls it. 

The normal way to delete an item is to use delete. 

If you need to move an item from one place in the hierarchy to another you can 
use takeItem() to remove the item from the list view and then insertItem() to 
put the item back in its new position. 

If a taken item is part of a selection in Single selection mode, it is 
unselected and selectionChanged() is emitted. If a taken item is part of a 
selection in Multi or Extended selection mode, it remains selected. 

Warning: This function leaves item and its children in a state where most 
member functions are unsafe. Only a few functions work correctly on an item 
in this state, most notably insertItem(). The functions that work on taken 
items are explicitly documented as such."

I've just confirmed it crashes - oh dear!

The QtJava bindings have a dispose() method although they have automatic 
garbage collection so it's only optional. Perhaps it would be a good idea to 
add that to the QtRuby runtime. Or maybe Qt::ListView.takeItem() should 
actually call delete on the Qt::ListViewItem.

-- Richard



More information about the Kde-bindings mailing list