Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Problem: Tester is not receiving signals from Emitter
- // To solve the problem that no signals are received there are two solutions
- // 1. Do not inherit from GLib.Object for class tester
- // 2. Move content of construtor MyClass() directly into main
- using Gtk;
- public class Emitter : GLib.Object {
- public signal void MySignal();
- public Emitter() {
- GLib.Timeout.add(4000, () => {
- warning("EMITTING TEST");
- MySignal();
- return true;
- });
- }
- }
- //public class Tester { // Receive of signal works
- public class Tester : GLib.Object { // Receive of signal does not work!
- public void test(Emitter e) {
- e.MySignal.connect(() => {
- warning("TESTER GOT SIGNAL");
- });
- }
- }
- public class MyClass : GLib.Object {
- public MyClass() {
- //If this code is inserted directly into main()
- //the signals are working as expected, too.
- var e = new Emitter();
- var t = new Tester();
- t.test(e);
- var window = new Window ();
- window.title = "Testprog";
- window.destroy.connect (Gtk.main_quit);
- window.show_all ();
- }
- }
- public int main(string[] args) {
- Gtk.init (ref args);
- var c = new MyClass();
- Gtk.main ();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement