On Dec 9, 2007 9:23 PM, Phil Housley <[EMAIL PROTECTED]> wrote:
>
> On 09/12/2007, Nguyen Thai Ngoc Duy <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > I tried this code:
> >
> > class MyComp : Gtk.Window {
> >         construct {
> >                 var b = new Gtk.Button.with_label("hellp");
> >                 b.clicked += on_clicked;
> >                 add(b);
> >         }
> >
> >         void on_clicked() {
> >                 GLib.stdout.printf("Help!\n");
> >         }
> >
> >         static int main(string[] p) {
> >                 Gtk.init(out p);
> >                 MyComp w = new MyComp();
> >                 w.show_all();
> >                 Gtk.main();
> >                 return 0;
> >         }
> > }
> >
> > The generated code for signal "clicked" was
> >
> > static void my_comp_on_clicked (MyComp* self) {
> >         g_return_if_fail (IS_MY_COMP (self));
> >         fprintf (stdout, "Help!\n");
> > }
> >
> > It should have been *_clicked(GtkWidget*, MyComp*). Was it code
> > generation broken or did I write something wrong? Vala revision was
> > 760.
> >
> > Thanks
> > --
> > Duy
>
> A signal handler function should be declared with a first argument of
> the type of the object emitting the signal (GtkButton).  Then vala
> will pass the object receiving it (MyComp) automatically as the
> user_data argument.
>
> void on_clicked(Gtk.Button btn) { ... }
> Should work fine.

Indeed. I looked at gtk+-2.0.vapi to know the prototype and it was

public signal void clicked ();

I changed to on_clicked(Gtk.Button btn) and it worked.
But vala did not notice me I passed a function that did not match the
signal prototype? :(

> Alternatively the equivalent lambda:
>
> b.clicked += btn => { ... };
>
> --
> Phil Housley
> _______________________________________________
> Vala-list mailing list
> [email protected]
> http://mail.gnome.org/mailman/listinfo/vala-list
>



-- 
Duy
_______________________________________________
Vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to