Re: Custom TreeModel

On 09.01.2010 16:08, Emmanuel Rodriguez wrote:
What I've noticed is that the data stored in the Gtk2::TreeIter is
really volatile and that it doesn't survive too long after a method
returns. Furthermore, only the 2 first elements of the TreeIter make it
back to the TreeModel methods intact. I also noticed that setting
references into the last 2 fields can yield strange situations.

As Kevin said, tree iters don't keep stuff you put into them alive for you. If you want to put any non-integer thing into an iter, you need to keep it alive some other way, for example by also storing it in a cache inside the tree model. This is also shortly explained in perldoc Gtk2::TreeModel / CREATING A CUSTOM TREE MODEL.

Here's a patch against your program that implements this. It also fixes an unrelated typo.

Is the Perl sample code wrong? Maybe I missed something..
Would it make sense to add it to the Gtk2-Perl examples, perhaps someone
could find it useful.

The example does this in GET_ITER:

        my $record = $self->{rows}[$n];
        return [ $self->{stamp}, $n, $record, undef ];

So the reference it puts into the iter is kept alive by $self->{rows}.

I guess a better explanation in the example and maybe also in the Gtk2::TreeModel docs would be useful. Care to write something up?

Description: Text Data

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]