Fwd: Re: Help with get_text() for Gtk3::Entry widget



>It's hard to say anything out of your snippet, because it's just a part of a whole code.
You are right, Yuri.  Thank you for pointing that out.

I played with your code and came up with the same problem I have been telling.
I still get this error message:
*** unhandled exception in callback:
***   Can't call method "get_text" on an undefined value at ./switch.pl line 28.
***  ignoring at /usr/share/perl5/Gtk3.pm line 137.

Following is the entire code:

#!/usr/bin/perl

use strict;
use warnings;

use Gtk3 -init;
 
sub test_get_text_calling {
    my ($button, $entries_ref) = @_;
    warn $$entries_ref->get_text();
}

my $window = Gtk3::Window->new('toplevel');
$window->signal_connect(delete_event => sub { Gtk3->main_quit() });


no strict 'refs';

my (@hbox, @button);
my $count = 1;
my $grid = Gtk3::Grid->new();
my $add_button = Gtk3::Button->new_with_label("add");
$add_button->signal_connect( clicked => sub {
        $hbox[$count] = Gtk3::HBox->new();
        ${ "entry_" . $count } = Gtk3::Entry->new;
        ${ "entry_" . $count }->signal_connect(
            'changed' => sub {
                warn "You've entered: ", ${ "entry_" . $count }->get_text();
            }
        );
        $button[$count] = Gtk3::Button->new('Call get_text()');
        $button[$count]->signal_connect('clicked',
                                \&test_get_text_calling,
                                \${ "entry_" . $count });
        $hbox[$count]->add(${ "entry_" . $count });
        $hbox[$count]->add($button[$count]);
        $grid->attach($hbox[$count],1,$count+1,2,1);
        $window->show_all();
        $count++;
    } # sub
); # signal_connect

    $grid->attach($add_button,1,1,1,1);
    $window->add($grid);
    $window->show_all();

use strict 'refs';

Gtk3->main();

Thank you for your help.

yoshi


-------- Original Message --------
Subject: Re: Help with get_text() for Gtk3::Entry widget
Date: Mon, 14 Apr 2014 12:17:10 +0400
From: Yuri Myasoedov <ymyasoedov yandex ru>
To: gtk-perl-list gnome org <gtk-perl-list gnome org>


14.04.2014, 09:40, "tsuyoshi okita" <825864 gmail com>:
> This is my code snippet:

It's hard to say anything out of your snippet, because it's just a part of a whole code. Try to provide minimal and complete test case that will show the problem.

BTW, here is my test case, that works fine:

#!/usr/bin/perl
use warnings;
use strict;
use Gtk3 -init;
 
sub test_get_text_calling {
    my ($button, $entries_ref) = @_;
    warn $entries_ref->[0]->get_text();
}

my $window = Gtk3::Window->new('toplevel');
$window->signal_connect(delete_event => sub { Gtk3->main_quit() });

no strict 'refs';
my $row = 1;

# Test item
${ "entry_" . $row } = Gtk3::Entry->new;

# Test item
my @test_array = ( ${ "entry_" . $row } );

${ "entry_" . $row }->signal_connect(
    'changed' => sub {
        warn "You've entered: ", ${ "entry_" . $row }->get_text();
    }
);

my $hbox = Gtk3::HBox->new();
my $button = Gtk3::Button->new('Call get_text()');
$button->signal_connect('clicked',
                        \&test_get_text_calling,
                        \ test_array);
$hbox->add(${ "entry_" . $row });
$hbox->add($button);
$window->add($hbox);
$window->show_all();
use strict 'refs';

Gtk3->main();
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list gnome org
https://mail.gnome.org/mailman/listinfo/gtk-perl-list




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