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




On Tue, Apr 15, 2014 at 2:56 AM, tsuyoshi okita <825864 gmail com> wrote:
*** unhandled exception in callback:
***   Can't call method "get_text" on an undefined value at ./switch.pl line 28.

This call to get_text() is in the closure for the "changed" signal.
The problem is $count: $count is a "free" variable wrt sub { ... }, i.e. $count is defined outside the sub's lexical scope.
But $count is defined in file scope and when the signal is emitted, its value is 2!
Hence the code executed is actually

   warn "You've entered: ", ${ "entry_2" }->get_text();

In your later post, you avoided this problem

        ${ "entry_" . $count }->signal_connect(
            'changed' =>  \&enter_get_text_calling,  \${ "entry_" . $count });

Now the "changed" closure (closure in the GObject sense) is a simple Perl sub (not using any free variables).
And the "data" argument (\${ "entry_" . $count }) to signal_connect is now evaluated at the time signal_connect() is called, hence uses the same value of $count as for the invocant of signal_connect().

Cheers, Roderich


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