Signal/slot in stand-alone program

hello,

I am a beginner and I tried a simple code to print the coordinates of the mouse. Everything is working well with CINT but when I try the same code in a stand alone program it doesn’t work. The compilation is ok but when I start the application I get the following message:

Error in TQObject::CheckConnectArgs: slot printEvent(int,int,int,TObject*) does not exist

Here is the code:

#include "rootheaders.hh"
#include <TROOT.h>
#include <TPad.h>
#include <TH1.h>
#include <TH2.h>
#include <TCanvas.h>
#include <RQ_OBJECT.h>


/////////////////////////////////////////////////////////////////////
/////////////////////// functions ///////////////////////////////////
//___________________________________________________________________
void printEvent(Int_t event, Int_t px, Int_t py, TObject *)
{
   //  print event type and current cursor position

   TCanvas *c = (TCanvas *) gTQSender;
   TPad *pad = (TPad *) c->GetSelectedPad();
   if (!pad) return;
   printf("event=%d, px=%d, py=%d, ", event, px, py);
   Float_t x = pad->AbsPixeltoX(px);
   Float_t y = pad->AbsPixeltoY(py);
   x = pad->PadtoX(x);
   y = pad->PadtoY(y);
   printf("x=%.3g, y=%.3g\n",x,y);
}


//___________________________________________________________________
int main(int argc, char *argv[])
{
   // simple test of Pad Event Dispatcher
   TApplication app("App", &argc, argv);
   gStyle->SetPalette(1);
   TCanvas *c1 = new TCanvas("c1", "Test of Canvas Event Signal",
                              900, 500);

   TPad *p1 = new TPad("p1","",0.01,0.05,0.49,0.95);
   TPad *p2 = new TPad("p2","",0.51,0.05,0.99,0.95);
   p1->Draw();
   p2->Draw();

   p1->cd();



   TH1F *hist1 = new TH1F("test1", "1-Dim hist filled manually",20, 1, 100);
   hist1->Draw();

   // print mouse coordinates
   c1->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", 0,0, "printEvent(Int_t,Int_t,Int_t,TObject*)");
   app.Run();

   return 0;

}

What am I doing wrong?
Thank you for your answers.

Hi,

do you have a dictionary for printEvent()? If not, create a header file containing the declaration (not the definition!) of it, i.e. sigslot.h

void printEvent(Int_t event, Int_t px, Int_t py, TObject *);

and a LinkDef.h:

#pragma link C++ function printEvent(Int_t event, Int_t px, Int_t py, TObject *);

and run rootcint on it:

rootcint -f sigslotdict.cxx -c sigslot.h LinkDef.h

Then build sigslotdict.cxx into a shared library that you either link against your main program or better yet dlopen at runtime. Once loaded the slot will be available.

Cheers, Axel.

Thank you very much for your answer.
It is working well now.
cheers,
Dala