Advertisement
Guest User

Untitled

a guest
Dec 17th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Vala 1.31 KB | None | 0 0
  1. // Problem: Tester is not receiving signals from Emitter
  2. // To solve the problem that no signals are received there are two solutions
  3. // 1. Do not inherit from GLib.Object for class tester
  4. // 2. Move content of construtor MyClass() directly into main
  5.  
  6.  
  7. using Gtk;
  8.  
  9. public class Emitter : GLib.Object {
  10.     public signal void MySignal();
  11.  
  12.     public Emitter() {
  13.         GLib.Timeout.add(4000, () => {
  14.             warning("EMITTING TEST");
  15.             MySignal();
  16.             return true;
  17.         });
  18.     }
  19. }
  20.  
  21. //public class Tester { // Receive of signal works
  22. public class Tester : GLib.Object { // Receive of signal does not work!
  23.     public void test(Emitter e) {
  24.         e.MySignal.connect(() => {
  25.             warning("TESTER GOT SIGNAL");
  26.         });
  27.     }
  28. }
  29.  
  30. public class MyClass : GLib.Object {
  31.     public MyClass() {
  32.  
  33.         //If this code is inserted directly into main()
  34.         //the signals are working as expected, too.
  35.         var e = new Emitter();
  36.         var t = new Tester();
  37.         t.test(e);
  38.  
  39.         var window = new Window ();
  40.         window.title = "Testprog";
  41.         window.destroy.connect (Gtk.main_quit);
  42.         window.show_all ();
  43.  
  44.     }
  45. }
  46.  
  47. public int main(string[] args) {
  48.  
  49.     Gtk.init (ref args);
  50.  
  51.     var c = new MyClass();
  52.  
  53.     Gtk.main ();
  54.     return 0;
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement