Re: Storing data in a TreeIter (custom TreeModel)
- From: muppet <scott asofyet org>
- To: gtk-perl list <gtk-perl-list gnome org>
- Subject: Re: Storing data in a TreeIter (custom TreeModel)
- Date: Wed, 26 May 2004 23:11:10 -0400
On Wednesday, May 26, 2004, at 07:32 PM, Zach Bean wrote:
The problem is this: I'm having some trouble actually storing data in
a TreeIter :o)
rule of thumb: since GtkTreeIters are ephemeral and give us no
destruction hooks, we cannot actually store data *in* Gtk2::TreeIters
-- you can only reliably store extra references to things you have
elsewhere. for example, you can put in an iter a reference to an
element of a list you keep in your model; the model's data structure
actually owns the reference, and the iter holds only a throwaway copy
of the reference. you can't really make an iter own anything. sorry.
thus...
return [$self->{_stamp}, ($id+1)-1, \$sibling, \$parent];
if $sibling and $parent are lexicals, and not copies of data existing
somewhere else, they will cease to exist at the end of this function,
and the iter will contain stale pointers.
The plus-one-minus-one thing seems to be necessary to get $id, which
came from the DB through DBI, into the TreeIter, which wants an
integer for the second field. For some reason, XS's SvIOK wouldn't
return true unless I did that. This seems to work well.
it may actually be a string, e.g., SvPOK is true. $id+0 should work as
well, and may be a little clearer.
--
He's so good, you're gonna rock, and if you don't rock, it's your own
fault.
-- kk, describing the perks of having a very good drummer.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]