# Make closing a TCanvas window close the application

**URL:** <https://root-forum.cern.ch/t/make-closing-a-tcanvas-window-close-the-application/7020>\
**Category:** ROOT\
**Created:** [August 22, 2008, 9:16am UTC](https://root-forum.cern.ch/t/make-closing-a-tcanvas-window-close-the-application/7020 "2008-08-22T09:16:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![raaij](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/898d66/32.png) [@raaij](https://root-forum.cern.ch/u/raaij)\
**Post date:** [August 22, 2008, 9:16am UTC](https://root-forum.cern.ch/t/make-closing-a-tcanvas-window-close-the-application/7020/1 "2008-08-22T09:16:27Z")

</div>

Dear Rooters,

I created a few macros that I use on various root files to plot some histograms. I created a small main function in each source file so that I can make a program out of it or run from inside root.

The main function is inside an #ifndef **CINT** , instanciates a TApplication and then runs it.

I would like to make it so that when I run the macro as a program, the program exits when I close one of the canvases that are created.

I tried canv-\>Connect(“CloseWindow()”, “TCanvas”, canv, “gApplication-\>Terminate()”);  
But I got the following error:  
Error in TQObject::CheckConnectArgs: signal TCanvas::CloseWindow() does not exist

How can I do this?

I have attached a bit of source that shows what I do.

Greetz, Roel  
[CanvasClose.C](https://root-forum.cern.ch/uploads/default/original/2X/b/bd76973ab124592d7967fc546a24558049c6e275.C) (741 Bytes)

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [August 22, 2008, 10:05am UTC](https://root-forum.cern.ch/t/make-closing-a-tcanvas-window-close-the-application/7020/2 "2008-08-22T10:05:23Z")

</div>

Hi

As you noticed, the Canvas::CloseWindow() signal doesn’t exist. Use Canvas::Closed() instead.  
Two examples:  
If the canvas has already been created and you have its pointer:

```auto
canv->Connect("TCanvas", "Closed()", "TApplication", gApplication, "Terminate()");

```

Otherwise, more generic way:

```auto
TQObject::Connect("TCanvas", "Closed()", "TApplication", gApplication, "Terminate()");

```

Cheers,  
Bertrand.

---

<div class="post-metadata">

**Author:** ![raaij](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/898d66/32.png) [@raaij](https://root-forum.cern.ch/u/raaij)\
**Post date:** [August 22, 2008, 10:45am UTC](https://root-forum.cern.ch/t/make-closing-a-tcanvas-window-close-the-application/7020/3 "2008-08-22T10:45:21Z")

</div>

That does the trick, thx!

Greetz, Roel
