Signals and Slots, RQ_OBJECT vs TQObject in CINT

From: Thomas Lauf <thl_at_hll.mpg.de>
Date: Fri, 27 May 2011 09:30:15 +0200


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 - 09:30:34 CEST

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