From $ROOTSYS/tutorials/gui/exec3.C

#include <TH1.h>
#include <TCanvas.h>
#include <TQObject.h>
#include "TROOT.h"

void exec3()
{
   // Example of using signal/slot in TCanvas/TPad to get feedback
   // about processed events. Note that slots can be either functions
   // or class methods. Compare this with tutorials exec1.C and exec2.C.
   //Author: Ilka Antcheva

   // Temporary work around the lack of automatic refresh of the list
   // when a script is reloaded.
   gROOT->GetListOfGlobalFunctions()->Delete();

   TH1F *h = new TH1F("h","h",100,-3,3);
   h->FillRandom("gaus",1000);
   TCanvas *c1=new TCanvas("c1");
   h->Draw();
   c1->Update();
   c1->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", 0, 0,
               "exec3event(Int_t,Int_t,Int_t,TObject*)");
}

void exec3event(Int_t event, Int_t x, Int_t y, TObject *selected)
{
   TCanvas *c = (TCanvas *) gTQSender;
   printf("Canvas %s: event=%d, x=%d, y=%d, selected=%s\n", c->GetName(),
          event, x, y, selected->IsA()->GetName());
}
 exec3.C:1
 exec3.C:2
 exec3.C:3
 exec3.C:4
 exec3.C:5
 exec3.C:6
 exec3.C:7
 exec3.C:8
 exec3.C:9
 exec3.C:10
 exec3.C:11
 exec3.C:12
 exec3.C:13
 exec3.C:14
 exec3.C:15
 exec3.C:16
 exec3.C:17
 exec3.C:18
 exec3.C:19
 exec3.C:20
 exec3.C:21
 exec3.C:22
 exec3.C:23
 exec3.C:24
 exec3.C:25
 exec3.C:26
 exec3.C:27
 exec3.C:28
 exec3.C:29
 exec3.C:30
 exec3.C:31
 exec3.C:32