Emit signal in class with the slot in another class

Hi,

I’m emitting a custom signal that I want to connect to a different class altogether. I made a simple program that demonstrates roughly what I want and attached it here. When button 2 or 4 is pressed, I expected the print out “Clicked from BasicA” and “Clicked from Main”. However, I only get the former. How do I get the latter?

Thanks in advance,
Surge
guitest.C (1.92 KB)

Hi Surge,

Use ACLiC: root [0] .x guitest.C+ root [1] Clicked from BasicA Clicked from Main Clicked from BasicA Clicked from Main

Cheers, Bertrand.

Hi Bertrand,

I get a huge amount of errors when I try ALCiC:

[code]root [0] .x guitest.C+
Info in TUnixSystem::ACLiC: creating shared library /home/j0n0/Desktop/testing/GUI/./guitest_C.so
Error: class,struct,union or type TGVerticalFrame not defined guitest.C:5:
Error: Symbol TGTextButton is not defined in current scope guitest.C:7:
Error: Symbol fButton1 is not defined in current scope guitest.C:7:
Error: Symbol TGTextButton is not defined in current scope guitest.C:8:
Error: Symbol fButton2 is not defined in current scope guitest.C:8:
Error: class,struct,union or type TGVerticalFrame not defined guitest.C:27:
Error: Symbol TGCheckButton is not defined in current scope guitest.C:30:
Error: Symbol fCheckButton is not defined in current scope guitest.C:30:
Error: class,struct,union or type TGMainFrame not defined guitest.C:46:
Warning: Error occurred during reading source files
Warning: Error occurred during dictionary source generation
!!!Removing /home/j0n0/Desktop/testing/GUI/guitest_C_ACLiC_dict.cxx /home/j0n0/Desktop/testing/GUI/guitest_C_ACLiC_dict.h !!!
Error: /usr/local/bin/rootcint: error loading headers…
Error in : Dictionary generation failed!
Info in : Invoking compiler to check macro’s validity
/home/j0n0/Desktop/testing/GUI/./guitest.C:5: error: expected class-name before ‘{’ token
/home/j0n0/Desktop/testing/GUI/./guitest.C:7: error: ISO C++ forbids declaration of ‘TGTextButton’ with no type
/home/j0n0/Desktop/testing/GUI/./guitest.C:7: error: expected ‘;’ before ‘’ token
/home/j0n0/Desktop/testing/GUI/./guitest.C:8: error: ISO C++ forbids declaration of ‘TGTextButton’ with no type
/home/j0n0/Desktop/testing/GUI/./guitest.C:8: error: expected ‘;’ before ‘
’ token
/home/j0n0/Desktop/testing/GUI/./guitest.C:10: error: ISO C++ forbids declaration of ‘TGWindow’ with no type
/home/j0n0/Desktop/testing/GUI/./guitest.C:10: error: expected ‘,’ or ‘…’ before ‘’ token
/home/j0n0/Desktop/testing/GUI/./guitest.C:24: error: expected identifier before numeric constant
/home/j0n0/Desktop/testing/GUI/./guitest.C:24: error: expected ‘,’ or ‘…’ before numeric constant
/home/j0n0/Desktop/testing/GUI/./guitest.C:24: error: ISO C++ forbids declaration of ‘ClassDef’ with no type
/home/j0n0/Desktop/testing/GUI/./guitest.C:25: error: expected ‘;’ before ‘}’ token
/home/j0n0/Desktop/testing/GUI/./guitest.C:25: error: expected ‘;’ before ‘}’ token
/home/j0n0/Desktop/testing/GUI/./guitest.C: In constructor ‘BasicA::BasicA(int)’:
/home/j0n0/Desktop/testing/GUI/./guitest.C:10: error: class ‘BasicA’ does not have any field named ‘TGVerticalFrame’
/home/j0n0/Desktop/testing/GUI/./guitest.C:10: error: ‘p’ was not declared in this scope
/home/j0n0/Desktop/testing/GUI/./guitest.C:10: error: ‘w’ was not declared in this scope
/home/j0n0/Desktop/testing/GUI/./guitest.C:10: error: ‘h’ was not declared in this scope
/home/j0n0/Desktop/testing/GUI/./guitest.C:11: error: ‘TString’ was not declared in this scope
/home/j0n0/Desktop/testing/GUI/./guitest.C:11: error: expected ‘;’ before ‘str’
/home/j0n0/Desktop/testing/GUI/./guitest.C:12: error: ‘str’ was not declared in this scope
/home/j0n0/Desktop/testing/GUI/./guitest.C:12: error: ‘n’ was not declared in this scope
/home/j0n0/Desktop/testing/GUI/./guitest.C:13: error: ‘fButton1’ was not declared in this scope
/home/j0n0/Desktop/testing/GUI/./guitest.C:13: error: expected type-specifier before ‘TGTextButton’
/home/j0n0/Desktop/testing/GUI/./guitest.C:13: error: expected ‘;’ before ‘TGTextButton’
/home/j0n0/Desktop/testing/GUI/./guitest.C:14: error: expected type-specifier before ‘TGLayoutHints’
/home/j0n0/Desktop/testing/GUI/./guitest.C:14: error: expected ‘)’ before ‘TGLayoutHints’
/home/j0n0/Desktop/testing/GUI/./guitest.C:14: error: ‘AddFrame’ was not declared in this scope
/home/j0n0/Desktop/testing/GUI/./guitest.C:18: error: ‘fButton2’ was not declared in this scope
/home/j0n0/Desktop/testing/GUI/./guitest.C:18: error: expected type-specifier before ‘TGTextButton’
/home/j0n0/Desktop/testing/GUI/./guitest.C:18: error: expected ‘;’ before ‘TGTextButton’
/home/j0n0/Desktop/testing/GUI/./guitest.C:19: error: expected type-specifier before ‘TGLayoutHints’
/home/j0n0/Desktop/testing/GUI/./guitest.C:19: error: expected ‘)’ before ‘TGLayoutHints’
/home/j0n0/Desktop/testing/GUI/./guitest.C: At global scope:
/home/j0n0/Desktop/testing/GUI/./guitest.C:10: warning: unused parameter ‘TGWindow’
/home/j0n0/Desktop/testing/GUI/./guitest.C: In member function ‘void BasicA::Click()’:
/home/j0n0/Desktop/testing/GUI/./guitest.C:23: error: ‘cout’ was not declared in this scope
/home/j0n0/Desktop/testing/GUI/./guitest.C:23: error: ‘Emit’ was not declared in this scope
/home/j0n0/Desktop/testing/GUI/./guitest.C: At global scope:
/home/j0n0/Desktop/testing/GUI/./guitest.C:27: error: expected class-name before ‘{’ token
/home/j0n0/Desktop/testing/GUI/./guitest.C:30: error: ISO C++ forbids declaration of ‘TGCheckButton’ with no type
/home/j0n0/Desktop/testing/GUI/./guitest.C:30: error: expected ‘;’ before ‘
’ token
/home/j0n0/Desktop/testing/GUI/./guitest.C:32: error: ISO C++ forbids declaration of ‘TGWindow’ with no type
/home/j0n0/Desktop/testing/GUI/./guitest.C:32: error: expected ‘,’ or ‘…’ before ‘’ token
/home/j0n0/Desktop/testing/GUI/./guitest.C:43: error: expected identifier before numeric constant
/home/j0n0/Desktop/testing/GUI/./guitest.C:43: error: expected ‘,’ or ‘…’ before numeric constant
/home/j0n0/Desktop/testing/GUI/./guitest.C:43: error: ISO C++ forbids declaration of ‘ClassDef’ with no type
/home/j0n0/Desktop/testing/GUI/./guitest.C:44: error: expected ‘;’ before ‘}’ token
/home/j0n0/Desktop/testing/GUI/./guitest.C:44: error: expected ‘;’ before ‘}’ token
/home/j0n0/Desktop/testing/GUI/./guitest.C: In constructor ‘BasicB::BasicB(int)’:
/home/j0n0/Desktop/testing/GUI/./guitest.C:32: error: class ‘BasicB’ does not have any field named ‘TGVerticalFrame’
/home/j0n0/Desktop/testing/GUI/./guitest.C:32: error: ‘p’ was not declared in this scope
/home/j0n0/Desktop/testing/GUI/./guitest.C:32: error: ‘w’ was not declared in this scope
/home/j0n0/Desktop/testing/GUI/./guitest.C:32: error: ‘h’ was not declared in this scope
/home/j0n0/Desktop/testing/GUI/./guitest.C:36: error: expected type-specifier before ‘TGLayoutHints’
/home/j0n0/Desktop/testing/GUI/./guitest.C:36: error: expected ‘)’ before ‘TGLayoutHints’
/home/j0n0/Desktop/testing/GUI/./guitest.C:36: error: ‘AddFrame’ was not declared in this scope
/home/j0n0/Desktop/testing/GUI/./guitest.C:38: error: ‘fCheckButton’ was not declared in this scope
/home/j0n0/Desktop/testing/GUI/./guitest.C:38: error: expected type-specifier before ‘TGCheckButton’
/home/j0n0/Desktop/testing/GUI/./guitest.C:38: error: expected ‘;’ before ‘TGCheckButton’
/home/j0n0/Desktop/testing/GUI/./guitest.C:39: error: expected type-specifier before ‘TGLayoutHints’
/home/j0n0/Desktop/testing/GUI/./guitest.C:39: error: expected ‘)’ before ‘TGLayoutHints’
/home/j0n0/Desktop/testing/GUI/./guitest.C: At global scope:
/home/j0n0/Desktop/testing/GUI/./guitest.C:32: warning: unused parameter ‘TGWindow’
/home/j0n0/Desktop/testing/GUI/./guitest.C:46: error: expected class-name before ‘{’ token
/home/j0n0/Desktop/testing/GUI/./guitest.C:51: error: ISO C++ forbids declaration of ‘TGWindow’ with no type
/home/j0n0/Desktop/testing/GUI/./guitest.C:51: error: expected ‘,’ or ‘…’ before ‘
’ token
/home/j0n0/Desktop/testing/GUI/./guitest.C:70: error: expected identifier before numeric constant
/home/j0n0/Desktop/testing/GUI/./guitest.C:70: error: expected ‘,’ or ‘…’ before numeric constant
/home/j0n0/Desktop/testing/GUI/./guitest.C:70: error: ISO C++ forbids declaration of ‘ClassDef’ with no type
/home/j0n0/Desktop/testing/GUI/./guitest.C:71: error: expected ‘;’ before ‘}’ token
/home/j0n0/Desktop/testing/GUI/./guitest.C:71: error: expected ‘;’ before ‘}’ token
/home/j0n0/Desktop/testing/GUI/./guitest.C: In constructor ‘Main::Main(int)’:
/home/j0n0/Desktop/testing/GUI/./guitest.C:51: error: class ‘Main’ does not have any field named ‘TGMainFrame’
/home/j0n0/Desktop/testing/GUI/./guitest.C:51: error: ‘p’ was not declared in this scope
/home/j0n0/Desktop/testing/GUI/./guitest.C:51: error: ‘w’ was not declared in this scope
/home/j0n0/Desktop/testing/GUI/./guitest.C:51: error: ‘h’ was not declared in this scope
/home/j0n0/Desktop/testing/GUI/./guitest.C:51: error: ‘kMainFrame’ was not declared in this scope
/home/j0n0/Desktop/testing/GUI/./guitest.C:51: error: ‘kVerticalFrame’ was not declared in this scope
/home/j0n0/Desktop/testing/GUI/./guitest.C:52: error: ‘kDeepCleanup’ was not declared in this scope
/home/j0n0/Desktop/testing/GUI/./guitest.C:52: error: ‘SetCleanup’ was not declared in this scope
/home/j0n0/Desktop/testing/GUI/./guitest.C:53: error: ‘gApplication’ was not declared in this scope
/home/j0n0/Desktop/testing/GUI/./guitest.C:53: error: ‘Connect’ was not declared in this scope
/home/j0n0/Desktop/testing/GUI/./guitest.C:54: error: ‘DontCallClose’ was not declared in this scope
/home/j0n0/Desktop/testing/GUI/./guitest.C:57: error: expected type-specifier before ‘TGLayoutHints’
/home/j0n0/Desktop/testing/GUI/./guitest.C:57: error: expected ‘)’ before ‘TGLayoutHints’
/home/j0n0/Desktop/testing/GUI/./guitest.C:57: error: ‘AddFrame’ was not declared in this scope
/home/j0n0/Desktop/testing/GUI/./guitest.C:60: error: expected type-specifier before ‘TGLayoutHints’
/home/j0n0/Desktop/testing/GUI/./guitest.C:60: error: expected ‘)’ before ‘TGLayoutHints’
/home/j0n0/Desktop/testing/GUI/./guitest.C:64: error: ‘MapSubwindows’ was not declared in this scope
/home/j0n0/Desktop/testing/GUI/./guitest.C:65: error: ‘Resize’ was not declared in this scope
/home/j0n0/Desktop/testing/GUI/./guitest.C:66: error: ‘MapRaised’ was not declared in this scope
/home/j0n0/Desktop/testing/GUI/./guitest.C: At global scope:
/home/j0n0/Desktop/testing/GUI/./guitest.C:51: warning: unused parameter ‘TGWindow’
/home/j0n0/Desktop/testing/GUI/./guitest.C: In destructor ‘virtual Main::~Main()’:
/home/j0n0/Desktop/testing/GUI/./guitest.C:68: error: ‘Cleanup’ was not declared in this scope
/home/j0n0/Desktop/testing/GUI/./guitest.C: In member function ‘void Main::Click()’:
/home/j0n0/Desktop/testing/GUI/./guitest.C:69: error: ‘cout’ was not declared in this scope
/home/j0n0/Desktop/testing/GUI/./guitest.C: In function ‘void guitest()’:
/home/j0n0/Desktop/testing/GUI/./guitest.C:74: error: ‘gClient’ was not declared in this scope
Error: Function guitest() is not defined in current scope :0:
*** Interpreter error recovered ***

[/code]

I’m don’t know why.

Well, as the compiler is invoked, you have to properly #include the necessary headers, as in any regular C++ source file… Just add theses lines at the beginning of your macro:

#include "TGFrame.h" #include "TGButton.h" #include "Riostream.h" #include "TApplication.h"

EDIT:
And you also have to implement the destructor for your classes. E.g. (at least):

virtual ~BasicB() {;} ... virtual ~BasicB() {;}
Cheers, Bertrand.

Thanks that did the trick. I’m still curious if there is any way of doing without running ALCiC?

Thanks again,
Surge

Yes, maybe with the RQ_OBJECT() macro, I’ll have to check…

Cheers, Bertrand.

OK, here is another way. Add RQ_OBJECT(“BasicA”) at the beginning of the BasicA class definition:

class BasicA : public TGVerticalFrame { RQ_OBJECT("BasicA") private: ... };
And then connect the signal and the slot like this:

Cheers, Bertrand.

Thanks again, it worked like a charm.

Surge