RE: Signals and Slots, RQ_OBJECT vs TQObject in CINT

From: Bertrand Bellenot <Bertrand.Bellenot_at_cern.ch>
Date: Fri, 27 May 2011 08:09:44 +0000


Hi Thomas,

The RQ_OBJECT("A") macro is to be used via the interpreter (.x SimpleRQ.C)

For a class inheriting from TQObject, one must use ACLiC and a dictionary has to be generated. To make SimpleTQ.C working, just add:

   ClassDef(MyClass, 0)
At the end of your class declaration, in order to create a dictionary for it, as shown below:

class MyClass : public TQObject {
private:

        Int_t fValue;
public:

	MyClass() { fValue=0; }
	Int_t GetValue() const { return fValue; }
	void SetValue(Int_t); // *SIGNAL*

	ClassDef(MyClass, 0)

};

Now you can interpret SimpleRQ.C:

root [0] .x SimpleRQ.C
value set to 11
A: 0
B: 11
value set to 79
value set to 79
A: 79
B: 79

Or execute SimpleTQ.C using ACLiC:

root [0] .x SimpleTQ.C+
value set to 11
A: 0
B: 11
value set to 79
value set to 79
A: 79
B: 79

Cheers, Bertrand.

-----Original Message-----
From: owner-roottalk_at_root.cern.ch [mailto:owner-roottalk_at_root.cern.ch] On Behalf Of Thomas Lauf Sent: 27 May 2011 09:30
To: roottalk (Mailing list discussing all aspects of the ROOT system.) Subject: [ROOT] Signals and Slots, RQ_OBJECT vs TQObject in CINT

Hello,

I have implemented an example given in the user's guide (p.401) and encountered some odd behaviour. The example connects two classes via the signal-slot mechanism and uses it to propagate a change of a variable from one class to the other (see attached files)

I have implemented one version (SimpleRQ.C) using the RQ_OBJECT macro (as shown in the user's guide) :

class MyClass {

   RQ_OBJECT("MyClass")
private:

   Int_t fValue;
public:

   MyClass() { fValue=0; }
   Int_t GetValue() const { return fValue; }    void SetValue(Int_t); // *SIGNAL*
};

void MyClass::SetValue(Int_t v) {

   if (v != fValue) {

     fValue = v;
     Emit("SetValue(Int_t)",v);
     cout << "value set to " << v << endl;
   }
}

and another where the classes inherit from TQObject (SimpleTQ.C):

class MyClass : public TQObject {
private:

   Int_t fValue;
public:

   MyClass() { fValue=0; }
   Int_t GetValue() const { return fValue; }    void SetValue(Int_t); // *SIGNAL*
};

void MyClass::SetValue(Int_t v) {

   if (v != fValue) {

     fValue = v;
     Emit("SetValue(Int_t)",v);
     cout << "value set to " << v << endl;
   }
}

In both cases I call a function that creates two instances A and B of MyClass, connects A::SetValue() to B::SetValue and then sets the value of A using the signal-slot to propagate this change to B:

MyClass *objA = new MyClass();
MyClass *objB = new MyClass();

        objA->Connect("SetValue(Int_t)","MyClass",objB,"SetValue(Int_t)"); objB->SetValue(11);
cout << "A: " << objA->GetValue() << endl; cout << "B: " << objB->GetValue() << endl; objA->SetValue(79);
cout << "A: " << objA->GetValue() << endl; cout << "B: " << objB->GetValue() << endl;

When running them in CINT, I experienced that the RQ_OBJECT-version succeeds while the TQObject-version fails with the error message:

Error in <TQObject::CheckConnectArgs>: signal TQObject::SetValue(int) does not exist

I've tried both versions in interpreted and compiled mode, with ROOT 5.26/00 and 5.29/03. Same effect in each configuration, RQ_OBJECT succeeds, TQObject fails. Does anybody have an idea why?

Regards, Thomas Lauf Received on Fri May 27 2011 - 10:09:51 CEST

This archive was generated by hypermail 2.2.0 : Fri May 27 2011 - 17:50:02 CEST