Return from TApplication when there is no canvas

Hi… I am trying to write a gui for interactive analysis chain. GUI is there to accept (many different) inputs from user. Once those inputs are accepted, i want the control to return to main() function so that I can perform rest of the things. GUI doesnot have a Canvas with File menu so that, one can do "QUIT ROOT"
to return from event loop. My main function looks like this…

int main(int argc, char* argv[]) {
TApplication theApp("App",&argc,argv);

string argv1,argv2,argv3 ;
int mode ;
argv1.append(theApp.Argv(1)) ;
argv2.append(theApp.Argv(2)) ;
argv3.append(theApp.Argv(3)) ;

mode = atoi(argv3.c_str()) ;

MyMainFrame* MMF =  new MyMainFrame(argv1.c_str(),argv2.c_str(),mode,gClient->GetRoot(),850,800);

theApp.Run(kTRUE);

fprintf(stderr,"Application ends\n") ;

theApp.Run() ;

return 0;
}

here… after pressing OK button on GUI, I expected that theApp will return control to main function ( Due to Run.(kTRUE) )…
and fpritnf() statement will be executed… but its not happening…
what am i missing ?? or doing wrong ??

Well, in the routine which manages your “OK” button, try to add:
gSystem->ExitLoop();
or, when you use “theApp.Run(kTRUE);”, you can also try to add:
gApplication->Terminate(0);

1 Like

Hi…
Thanks… Both of them work…
However, if in main function , I comment the second theApp.Run() statement code crashes after executing fprintf() statement … Why is that ? I dont really understand , how theApp.Run() works ?

Hello,
Guidelines on terminating a TApplication is something that is clearly lacking in Root.
I have a program:
int main(){
TApplication app(“myapp”, 0, 0)
Draw some histograms
app.Run(kTRUE);
printf(“Press Enter\n”);
cin.get();
app.Terminate();
}
I expect that the histograms will be displayed on the screen until the user presses Enter. However, the program never gets past the line app.Run(kTRUE), and I have to resort to such savage methods of breaking the program as Ctrl + C.

Clear explanation of how to terminate TApplication is very much needed.
Regards,
Viesturs

You can return from “theApp.Run(kTRUE);” just by using “any canvas main menu” -> “File” -> “Quit ROOT”.

1 Like

Thanks, it works.