[Vala] How to connect a delegate to a signal?
- From: "G.S.Alex" <sthots gmail com>
- To: vala-list gnome org
- Subject: [Vala] How to connect a delegate to a signal?
- Date: Mon, 7 Dec 2009 20:47:12 +0800
I used to think the delegate could be used just like method it self .
But when I try to connect a delegate to a signal , i got the error:
------------------------------------------------
t.vala:24.29-24.29: error: Argument 1: Cannot convert from `DN' to
`Foo.some_event'
foo.some_event.connect (d);
------------------------------------------------
So, how could I do that?
my test code:
------------------------------------------------
public class Foo : Object {
public signal void some_event (); // definition of the signal
public void method () {
some_event (); // emitting the signal
(callbacks get invoked)
}
}
delegate void DN();
static void callback_a () {
stdout.printf ("Callback A\n");
}
static void callback_b () {
stdout.printf ("Callback BB\n");
}
static int main (string[] args) {
var foo = new Foo ();
foo.some_event.connect (callback_a); // connecting the
callback functions
DN d = callback_b;
//d();
foo.some_event.connect (d);
foo.method ();
return 0;
}
------------------------------------------------
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]