Re: GTK2::Button retrieved from Tie::IxHash hash value does not render



On Thu, Jul 21, 2011 at 16:59, Terrence Brannon <schemelab gmail com> wrote:
The simple program below:

use Gtk2 -init;
use Tie::IxHash;
# Gtk2->init; works if you didn't use -init on use
my $window = Gtk2::Window->new('toplevel');
my $vbox = Gtk2::VBox->new (FALSE, 0);
$window->add($vbox);
#tie my %button, Tie::IxHash;
$button{qbimport} = Gtk2::Button->new('Quickbooks Import');
$button{qbimport}->signal_connect( clicked => \&qbimport );
$button{quit} = Gtk2::Button->new('Quit');
$button{quit}->signal_connect( clicked => sub { Gtk2->main_quit } );

$vbox->add($button{$_}) for (keys %button);
$window->show_all;
Gtk2->main;
sub qbimport { }

works just fine if you dont tie the %button hash with Tie::IxHash.
However, if you do, then it fails with the error:

Gtk2::Button=HASH(0x29b317c) is not of type Gtk2::Widget at v2.pl line 19.
It seems that Tie::IxHash is storing the string representation of the
buttons instead of the real values.

Try the following:

$button{qbimport} = [ Gtk2::Button->new('Quickbooks Import') ];
$button{qbimport}[0]->signal_connect( clicked => \&qbimport );

$vbox->add($button{$_}[0]) for (keys %button);

-- 
Emmanuel Rodriguez



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