Search code examples
root-framework

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 and the terminal doesn’t prompt. Any suggestions ?

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

Solution

  • Thanks to @bellenot from root-forum for providing the following solution. Apparently, for ROOT 6 & above, This should be done with a TRootCanvas object.

    #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;
    }