Re: [Vala] broken gtk+ binding?



On 09/12/2007, Nguyen Thai Ngoc Duy <pclouds gmail com> 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.  Alternatively the equivalent lambda:

b.clicked += btn => { ... };

-- 
Phil Housley



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