How to quit ROOT inside a TApplication

Hi,

I have a C++ program where I have :

int main(int argc, char **argv)
{
 (...)

  TApplication theApp("theApp", &argc, argv) ;

(... my program)

  theApp.Run();

  return 0;
} // main

When I launch the program a few canvas are displayed and usually I just quit using File->Quit ROOT in one of the canvas, How could I do it automatically ?

Thanks a lot in advance that may save me a lot of time !!!

Hi,

This is what you need:

Up to you to decide when to call it (I don’t know what you mean by “automatically”…)

Cheers, Bertrand.

Thanks a lot, I meant by automatically just at thr end, so I guess just before return 0 ;

Still I’ve tried it and nothing happens, should I add something like an exit in top of it:

  theApp.Run();

  gApplication -> Terminate(0);
  exit(1) ;

  return 0;
} // main

Thanks in advance

Hi,

Sorry, but when you create a TApplication, you have to control it, there is no “automatic termination”…
(i.e. you may choose to terminate when there are no more open windows, no more input/output, no more open file, …)

Cheers,
Bertrand.

Ok then, but I think there should have such a thing, or am I just using the wrong class ?
Because when creating lots of batches of canvas using some code which has been quite improved I don’t see the point to stand in front of the screen just to quit at the ned of each batch.

What method would you sugggest ?

Thanks

Do you need something like TQtRootSlot class offers?
See: root.cern.ch/root/html/TQtRootSlot.html:

Valeri,
as far as I understood in his/her case all created canvases are
not closed, so “lastWindowClosed” will not work.

I think it’s possible to use (somehow)
root.cern.ch/root/html/TApplicat … tIdleTimer

Bertrand, could try this? Sorry, not by myself because of busy

Regards. Valeriy

Hi,

Please try the attached demo app. It creates three canvases, save them in gif format and then exit.

Cheers,
Bertrand.
test.cxx (1.79 KB)

[quote=“bellenot”]Hi,

Please try the attached demo app. It creates three canvases, save them in gif format and then exit.

Cheers,
Bertrand.[/quote]

Just a very silly comment :smiley:

It doesn’t matter too much what you call a source file, but make sure you don’t name the executable ‘test’. If you have ‘.’ in your path people usually just type

unix> test

And your code won’t run (you’ll run the unix command ‘test’ instead which appears to do nothing). Many people have lost many hours because of this. :smiley:

Cheers,
Charles

Hi Charles,

Sorry, I didn’t pay attention to this (I mostly develop on Windows) :blush:
And thank you very much for the tip, it is good to know! :wink:

Cheers,
Bertrand.

[quote=“Kaeguri”]Hi,

I have a C++ program where I have :

int main(int argc, char **argv)
{
 (...)

  TApplication theApp("theApp", &argc, argv) ;

(... my program)

  theApp.Run();

  return 0;
} // main

[/quote]Can you give us an example what your (... my program)does ? Probably you do not need to call theApp.Run(); at all. May be, what you need can be done with the simple ROOT session:root.exe -q <you program>With the information your have provided it is hard to make an advice.