Destroying widget in own callback



The attached code produces the error message when the ComboBox is changed:

GLib-GObject-CRITICAL **: g_object_notify: assertion `G_IS_OBJECT
(object)' failed at ../assertiondemo.pl line 13.

which is not surprising, given that the ComboBox is being destroyed in
its own callback.

In my application, it would be rather cumbersome to have to avoid
destroying and recreating the widget in this way. Is there any other
way of getting rid of the error message?

Regards

Jeff Ratcliffe

#!/usr/bin/perl

use warnings;
use strict;
use Gtk2 -init;

my $window = Gtk2::Window -> new;
$window -> signal_connect ( 'delete-event' => sub { Gtk2 -> main_quit } );
my $main_vbox = Gtk2::VBox -> new;
$window -> add ( $main_vbox );
update_options();
$window -> show_all;
Gtk2 -> main;


sub update_options {
 foreach ($main_vbox -> get_children) {
 $_ -> destroy;
}
 my $combob = Gtk2::ComboBox->new_text;
 foreach ( ( 1, 2, 3 ) ) {
 $combob->append_text ($_);
}
 $combob -> set_active (0);
 $combob -> signal_connect (changed => sub {
 update_options();
});
 $main_vbox -> add ($combob);
$main_vbox -> show_all;
}



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