Re: using the signal_connect_object() method




Rob Benton said:
Hey I have a question about the signal_connect_object() method.  On the
gtk-perl homepage all I can find about this method is that the 3rd
argument is supposed to be a slot_object.  What exactly is that?  I've
been able to use that function in C on just a regular gtk widget.  But I
must be missing something in perl.

Gtk-Perl is obsolete.  Please don't use it to write new code.

Gtk2-Perl is available from http://gtk2-perl.sf.net/


I have a textbox I want updated when I press a button.

$button->signal_connect_object( 'clicked', \&update_text, $textbox);

the code above gives me this error:

Can't call method "Gtk::Text=HASH(0x828dd6c)" on unblessed reference at
/usr/lib/perl5/Gtk.pm line 199

according to Gtk.pm, it is implemented like this:

  sub signal_connect_object {
        my ($obj, $signal, $slot_object, $handler, @data) = @_;

        $obj->signal_connect($signal, sub {
                # throw away the object
                shift;
                $slot_object->$handler(@_);
        }, @data);
  }

and you'd use it as

  $button->signal_connect_object ('clicked', $text, 'update_text');

that is, a method *name*, in the wrong order.


on second thought, don't use this method.  use a closure, instead:

  $button->signal_connect (clicked => sub { $text->update_text });

that's what the wrapper is doing under the hood, but very oddly.



and on third thought, <broken record>don't use Gtk-Perl, use Gtk2-Perl</broken
record>.


-- 
muppet <scott at asofyet dot org>



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