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

Hans Fugal hans at fugal.net
Mon Jun 28 17:32:22 UTC 2004


/* Quoth Richard Dale <Richard_Dale at tipitina.demon.co.uk>
   on Mon, 28 Jun 2004 at 17:23 +0100
   in <200406281723.37068.Richard_Dale at tipitina.demon.co.uk> */

> 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:

Agreed, but according to the docs it should be save to takeItem and
subsequently insertItem somewhere else. This seems to be the only way to
move an item around, unless I'm missing something.

> 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.

The problem is Qt wants you to delete a QListViewItem to remove it from
the tree. It probably seemed like a neat trick in C++. But in GC
languages the GC happens after you lose all refernces to it, not the
other way around. I'm assuming that if you use takeItem and then drop
it, the GC will take care of it. If not, well at least it would 'work',
even if there's a memory leak there. Having takeItem actually call
delete would break the takeItem/insertItem semantics in the docs.

-- 
 .O.  Hans Fugal            | De gustibus non disputandum est.
 ..O  http://hans.fugal.net | Debian, vim, mutt, ruby, text, gpg
 OOO                        | WindowMaker, gaim, UTF-8, RISC, JS Bach
---------------------------------------------------------------------
GnuPG Fingerprint: 6940 87C5 6610 567F 1E95  CB5E FC98 E8CD E0AA D460



More information about the Kde-bindings mailing list