Standalone root application doesn't terminate upon closing a canvas

I’m making a standalone root application which should terminate upon closing a canvas. The following is my experimental code.

#include "TROOT.h"
#include "TApplication.h"
#include "TCanvas.h"

int main(){
TApplication *myapp=new TApplication("myapp",0,0);
TCanvas *c1 =new TCanvas("c1","Canvas Test",800,800);
c1->Connect("TCanvas", "Closed()", "TApplication",gApplication, "Terminate()");
myapp->Run();
return 0;
}

The code compiles without any warnings. The canvas opens when I run it. But when I close the the canvas, application doesn’t terminate. terminal doesn’t prompt.

Any idea what I’m doing wrong?
Thanks in advance

_ROOT Version: 6.20
_Platform: Ubuntu 20.04
_Compiler: g++


Try with:

#include "TROOT.h"
#include "TApplication.h"
#include "TCanvas.h"
#include "TRootCanvas.h"

int main()
{
   TApplication *myapp = new TApplication("myapp", 0, 0);
   TCanvas *c1 = new TCanvas("c1","Canvas Test",800,800);
   TRootCanvas *rc = (TRootCanvas *)c1->GetCanvasImp();
   rc->Connect("CloseWindow()", "TApplication", gApplication, "Terminate()");
   myapp->Run();
   return 0;
}
2 Likes

@bellenot That does the trick !!! Thank you very much !!!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.