Problem with signal/slot in a wrapper class

Hi,
I’m trying to create a GUI and I was wondering if it is possible to connect a signal that connects to a slot of a class that is one level higher, i.e.

[code]class wrapper
{
RQ_OBJECT(“wrapper”)
private:
inner * object;

public:
Slot_Function(Bool_t);
wrapper();

};

wrapper::wrapper()
{
inner *ins=new inner();

}


class inner
{
RQ_OBJECT(“inner”)
private:
TGCheckButton *tg;

public:
inner();

}

inner::inner()
{

TGCheckbutton *tg=new TGCheckbutton(…);

tg->Connect(“Toggled(Bool_t)”,“wrapper”,0,“Slot_Function(Bool_t)”);
}[/code]

This is for a standalone program, so I create dictionaries.
*I am not able to link separate dictionaries for both files, because of a conflict and redeclaration (but it could be I’m doing something wrong, as I copied a Makefile).
*When I link the dictionary only for the inner class, I am able to connect to a slot that is a part of the inner class, while a method from the wrapper class says, that slot doesn’t exist.
*When I link the dictionary only for the wrapper class neither the slot from the wrapper or inner class is found.

  • edit, I tried to create a Dictionary from both files like in:

wrapperDict.$(SrcSuf): wrapper.h inner.h wrapperLinkDef.h @echo "Generating dictionary $@..." @rootcint -f $@ -c $^

but it still doesn’t see the wrapper slot, while seeing the inner slot.

if I put in the ClassDef, and ClassImp macros in the inner class it compiles with same result, but putting them in the outer class makes the compilation crash at linking…

I’m using Root 5.12/00f on Scientific Linux.

I’ll be grateful for any suggestions,
cheers,
Andrzej

Hi Andrzej,

You have to pass the pointer of the receiver class in the Connect() method (the third argument wich is 0 in your case). Please take a look at your modified code below.

[code]class wrapper {

RQ_OBJECT(“wrapper”)

private:
inner *object;

public:
Slot_Function(Bool_t);
wrapper();
};

wrapper::wrapper()
{
object = new inner(this);
}


class inner {
RQ_OBJECT(“inner”)

private:
TGCheckButton *tg;

public:
inner(wrapper *w);
}

inner::inner(wrapper *w)
{
tg = new TGCheckbutton(…);
tg->Connect(“Toggled(Bool_t)”,“wrapper”,w,“Slot_Function(Bool_t)”);
}[/code]
If this still doesn’t work, please give more details on what is failing.

Bertrand.

Thanks that does what I wanted. It’s a very neat solution, I didn’t know why I didn’t think of that.

Anyway I still had a problem, but it seems that it was because I had the wrapperLinkDef.h wrong. Now it connects.

Thanks for the help!
Andrzej