Question about the Sender/Reciver Object communication

I have a questions to the TQObject communication mechanism.
In my code i open several canvases and store the pointers to them in an array. Now if one of these canvases is closed with the mouse, it is destroyed and my stored pointer is not valid anymore.

Now my question: Can I use the emitted Closed() Signal from the canvas to retrieve, which canvas was closed and set the corresponding pointer in my array to NULL?
I thought the GetSender() function would to this but I could not get it to work so far.
Thank a lot for any help.


Here is an example:[code]TList *canvasList;

void disconnect()
TCanvas *c = dynamic_cast<TCanvas *>((TQObject *)gTQSender);
if (c && canvasList->FindObject(c->GetName())) {
std::cout << c->GetName() << " has been removed" << std::endl;

void addCanvas()
TString cname = TString::Format(“c%d”, canvasList->GetSize());
TCanvas *c = new TCanvas(cname.Data(), cname.Data(), 800, 600);
c->Connect(“Closed()”, 0, 0, “disconnect()”);
std::cout << “TCanvas " << cname.Data() << " has been added” << std::endl;

void testCanvasList()
canvasList = new TList;
for (int i=0;i<5;++i) {
Cheers, Bertrand.

I understood the following from your example:

  1. When the canvas is created you connect the “Closed()” Signal with your function “disconnect()” to remove it from the array.
  2. When disconnect() is called you get a pointer to the sender object from gTQSender.
  3. If the pointer is valid and in your canvas Array you remove it.

Unfortunatly I have a problem with your solution. In my code the gTQSender seems not to set the right pointer, i get a zero pointer out.
I am using a slightly different connection for the canvases, as everything happens in a self written class MyMainWin.

void MyMainWin::OpenCanvas(){		
        const char* name=ListBoxImages->GetEntry(id)->GetTitle();
        TCanvas* canvas=new TCanvas(name,name);
        canvases->AddAt(canvas,id); // a TObjArray* defined in the constructor of MyMainWin

void MyMainWin::ClosedCanvas()
	TCanvas *c = dynamic_cast<TCanvas*>((TQObject *)gTQSender);
        cout<<"Pointer: "<< c<< endl; 
        // I get a zero here, instead of a one !!

	if (c && canvases->FindObject(c->GetName())) {
		int id=canvases->IndexOf(c);
		std::cout << c->GetName() << " has been removed" << std::endl;


Can you try to replace:TCanvas *c = dynamic_cast<TCanvas*>((TQObject *)gTQSender);by:TCanvas *c = (TCanvas *)gTQSender;This should work.

Cheers, Bertrand.

This works.
Thanks a lot.