Hi Kirill, Fons,
Fons Rademakers wrote:
>
> > 2. Is it nessesary to have the class inheriting from TQObject if i wonna
> > make the signal-slot connection to it methods? Connection to non ROOT
> > enable class is possible in interpreter, but i can't make this code
> > operational
> > as standalone.
> >
> You obviously don't have to inherit from TQObject if you won't make
> any signal/slot connections to its methods. What is the problem in
> stand alone code? Show me an example.
Making standalone exectutabable program which uses signal/slot connections
you should remember that slot SHOULD be a method of class with dictionary
( for compiled class it means "having ClassDef, ClassImp and being passed through
rootcint ) ... but using ACLiC (Automatic Compiler of Shared Library for CINT)
very simplifies this procedure.
Check the following example:
- Cut the code below and save it as tst.C
- run root
- compile and load the script with ACLiC
root[].L tst.C++
that will create tst_C.so file which will contain A class with dict
- run it
root[]rtfirst()
- compile tst.C as standalone executable program:
g++ -o tst tst.C `root-config --cflags --libs` -DSTANDALONE
- run it
$./tst
Regards. Valeriy
------------------------------ tst.C ---------------------------------
#include <TQObject.h>
#include <RQ_OBJECT.h>
///////////////////////////////////////////////////////////////////////
class A
{
RQ_OBJECT()
private:
Int_t fValue; //
Int_t fValues[3];
const Text_t* fText;
public:
A():fValue(0) { }
~A() { }
void SetValue(Int_t value); //*SIGNAL*
void SetValues(Int_t*); //*SIGNAL*
void SetText(const Text_t*); //*SIGNAL*
void SetValues(Int_t v1,Int_t v2,Int_t v3); //*SIGNAL*
void PrintValue() const { printf("value=%d\n",fValue); }
void PrintValues() const { for(int i=0; i<3; i++ ) printf("value[%d]=%d\n",i,fValues[i]); }
void PrintText() const { printf("\ntext:\t%s\n",fText); }
};
//___________________________________________________________________
void A::SetValue(Int_t value)
{
// Set new value.
// Emit signal "SetValue(Int_t)" with a single parameter
if(value!=fValue) {
fValue=value;
Emit("SetValue(Int_t)",fValue);
}
}
//___________________________________________________________________
void A::SetValues(Int_t* values)
{
// Set new values
// Emit signal "SetValues(Int_t*)" with pointer
// to Int_t as parameter
if( values != fValues ) {
for(int i=0; i<3; i++) fValues[i] = values[i];
Emit("SetValues(Int_t*)",(long)fValues);
}
}
//___________________________________________________________________
void A::SetValues(Int_t v0, Int_t v1, Int_t v2)
{
// Set new values
// Emit signal "SetValues(Int_t,Int_t,Int_t)"
// with three parameters.
long args[3];
if( v0 != fValues[0] ||
v1 != fValues[1] ||
v2 != fValues[2] ) {
args[0] = fValues[0] = v0;
args[1] = fValues[1] = v1;
args[2] = fValues[2] = v2;
Emit("SetValues(Int_t,Int_t,Int_t)",args);
}
}
//___________________________________________________________________
void A::SetText(const Text_t* text)
{
// Set new text.
// Emit signal "SetText(Text_t*)"
if( text!=fText ) {
fText = text;
Emit("SetText(Text_t*)",fText);
}
}
/////////////////////////////////////////////////////////////////////
//___________________________________________________________________
void rtfirst()
{
// Simple tests on signals, slots and connections
A* a = new A();
A* b = new A();
a->Connect("SetValue(Int_t)","A",b,"SetValue(Int_t)");
a->Connect("SetValues(Int_t,Int_t,Int_t)","A",b,"SetValues(Int_t,Int_t,Int_t)");
a->Connect("SetValues(Int_t*)","A",b,"SetValues(Int_t*)");
a->Connect("SetText(Text_t*)","A",b,"SetText(Text_t*)");
printf("\n******* Test of SetValue(Int_t) signal *******\n");
b->SetValue(10);
printf("\n\t***** b before ******\n");
b->PrintValue();
a->SetValue(20);
printf("\t***** b after a->SetValue(20) ******\n");
b->PrintValue();
printf("\n******** Test of SetValues(Int_t,Int_t,Int_t) signal ");
printf("********\n");
b->SetValues(10,20,30);
printf("\n\t***** b before ******\n");
b->PrintValues();
a->SetValues(1,2,3);
printf("\n\t***** b after a->SetValues(1,2,3) ******\n");
b->PrintValues();
printf("\n******** Test of SetValues(Int_t*) signal *******\n");
Int_t qq[3] = { 40,50,60 };
a->SetValues(qq);
printf("\n\t***** b after a->SetValues(Int_t*) ******\n");
b->PrintValues();
printf("\n******* Test of SetText(Text_t*) signal *******\n");
b->SetText("ABRACADABRA\n");
b->PrintText();
a->SetText("Signal-Slots are working!\t\n");
b->PrintText();
}
///////////////////////////// Main program ////////////////////////
#ifdef STANDALONE
#include <TROOT.h>
#include <TSystem.h>
#include <TInterpreter.h>
//---- Main program -------------------------------------------------
TROOT root("tst","Test of signal/slots");
int main(int argc, char **argv)
{
gSystem->Load("./tst_C");
rtfirst();
return 0;
}
#endif //STANDALONE
------------------------------ tst.C ---------------------------------
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:39 MET