Re: Displaying graphs before main() returns

From: Rene Brun <Rene.Brun_at_cern.ch>
Date: Tue, 30 May 2006 08:37:03 +0200


If you create your own executable (with a main) and this application has graphics,
you must create a TApplication object. See example in $ROOTSYS/test/hworld.cxx
It is in general a very bad idea to create your own main program. You better execute scripts
from the ROOT prompt.

Rene brun

doeAlex Mott wrote:
> Hi,
>
> I am trying to simply display a set of graphs in a some canvases, and
> then prompt the user to save the file. I create the TCanvases using
> TCanvas *mycanv = new TCanvas("mycanv","name");
> and then draw to it using the Draw() method from a TH1F, and nothing
> is displayed (the Canvas isn't even created. Even if the canvas is
> previously created in a different instance of the program, nothing is
> drawn to it. Only once the program has finished, and the main loop
> has returned are the canvases created and the TGraphs plotted to the
> canvases. If anyone knows how to fix that, it would be much appreciated.
>
> Here is some code which generates the problem (this should compile on
> any build as far as I know):
> #include <iostream>
> #include "TROOT.h"
> #include "TH1.h"
> #include "TCanvas.h"
>
> int main(){
> char save='n';
> TH1F *qw = new TH1F("qw","test",100,0,5);
> for(int i=0;i<100;i++)
> qw->Fill(1);
> TCanvas *qe = new TCanvas("qe","");
> qw->Draw();
> cout << endl << "Save?: (y/n)";
> cin >> save;
> return 0;
> }
>
>
>
>
> Alexander Mott
> armott_at_mit.edu
> Undergraduate
> Department of Physics
> Massachusetts Institute of Technology
>
>
Received on Tue May 30 2006 - 08:37:10 MEST

This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:31:58 MET