Re: Another silly newbie question



Fred. Oger said:
Could someone tell me how I could pass several args to my callback
function ?

$okbutton->signal_connect('clicked',\&ValidateLogin,$fieldUid,$fieldPwd);

use a reference to a deeper data structure, for example a hash reference, and
rewrite your callbacks to accept it:

  $okbutton->signal_connect (clicked => \&validate,
                             { uid => $fieldUid, pwd => $fieldPwd });
  sub validate {
      my ($button, $data) = @_;
      # $data->{ui} amd $data->{pwd} are now valid
  }

or use a perl closure to avoid the need (not always possible):

  $okbutton->signal_connect (clicked => sub {
                  # you can get to any variable in the same scope as
                  # the signal_connect statement...
                  do_something_with ($fieldUid, $fieldPwd, etc);
               });



It works perfectly with gtk1.2 but it's not accepted in Gtk2 ?

gtk-perl's argument handling for signal callbacks was broken, because the
variable-length list of data and the fact that the user data preceded the
other parameters meant you had no idea where in the arglist the expected
parameters were going to be, and the C API reference no longer applied
directly.

gtk2-perl made a conscious decision not to carry this behavior forward. 
signal handlers in gtk2-perl get exactly the arguments listed in the C API
reference, and signal_connect takes a single data argument.  since you can
pass any perl scalar through that single data argument, everything is peachy.


-- 
muppet <scott at asofyet dot org>



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