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

Re: Autoupdating EntryCompletion (was Selectively trapping keypresses)



Jeffrey Ratcliffe wrote:
> On 16/04/07, muppet <scott asofyet org> wrote:
>> Everything's good right up until the end.  ;-)
>
> I've added a couple of callbacks to get new entries into the ListModel
> to which the EntryCompletion is bound. Selecting entries several times
> from the EntryCompletion is giving me:
>
> Gtk-CRITICAL **: gtk_list_store_get_value: assertion `VALID_ITER
> (iter, list_store)' failed at ./EntryCompletion3.pl line 105.
> GLib-GObject-CRITICAL **: g_object_set_property: assertion `G_IS_VALUE
> (value)' failed at ./EntryCompletion3.pl line 105.
>
> I've attached the code.

I couldn't reproduce that after tinkering for just a few moments, but i think
i see it in the code...

> What am I doing wrong?

Any change to a TreeModel invalidates existing TreeIters.


> $cmp_model -> signal_connect('row-inserted' => sub {
>   my ($model, $path, $iter) = @_;
>   my ($val) = $cmp_model->get($iter, 0);
> warn "inserted $val\n";
>
> # Weed out duplicates
>   my $iter2 = $cmp_model->iter_next($iter);
>  while ($iter2) {
>   my ($val2) = $cmp_model->get($iter2, 0);
> warn "list $val2\n";
>   if ($val eq $val2) {
> warn "removing $val2\n";
>    $cmp_model->remove ($iter2);
> warn "removed $val2\n";
>   }
>   else {
>    $iter = $iter2;
>   }
>   $iter2 = $cmp_model->iter_next($iter);

$iter has potential to be invalid here, as the model may have been changed by
the preceding statements.

>  }
> });

Try using a TreePath to point to the current row while modifying the model, or
at the very least restarting the iteration after modifications.


-- 
muppet <scott at asofyet dot org>




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