Opening a canvas in a program

Dear Rooters,

I’m trying to open a root-canvas inside a c++ program. See the following piece of code


/* This macro can be compiled with
g++ -g -O2 -Wall `root-config --cflags --libs` analab.cc -o analab 
*/

#include <stdlib.h>
#include <TStyle.h>
#include <TFile.h>
#include <TCanvas.h>
#include <TBox.h>
#include <TH1.h>
#include <TF1.h>
#include <TPad.h>
#include <TPaveLabel.h>
#include <TPostScript.h>
#include "TClonesArray.h"
#include "TObject.h"
#include "TMap.h"
#include "TTree.h"
//#include "Riostream.h"
#include <vector>



int main(){

  //gROOT->Reset();
  TCanvas *c1 = new TCanvas("c1", "c1",136,24,699,499);
  c1->SetFillColor(0);
  c1->WaitPrimitive("\n");
 
  return 0;
}

The program compiles with the directives given at the beginning of the source code.
It then runs but nothing opens.

In this case I am working with root version 3.05_07-rfdc.

Any idea what might go wrong ???

Thanks in advance.

Roman

:stuck_out_tongue:

Actually, it’s good if one can answer his/her own questions bt oneself.


/* This macro can be compiled with
g++ -g -O2 -Wall `root-config --cflags --libs` analab.cc -o analab 
*/

#include <stdlib.h>
#include <TStyle.h>
#include <TFile.h>
#include <TCanvas.h>
#include <TBox.h>
#include <TH1.h>
#include <TF1.h>
#include <TPad.h>
#include <TPaveLabel.h>
#include <TPostScript.h>
#include <TApplication.h>
#include "TClonesArray.h"
#include "TObject.h"
#include "TMap.h"
#include "TTree.h"
//#include "Riostream.h"
#include <vector>
//#include "Event.h"
TH1F* h2f;

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

  //gROOT->Reset();
  TApplication fooApp("fooApp", &argc, argv);
  TCanvas *c1 = new TCanvas("c1", "c1",136,24,699,499);
  c1->SetFillColor(0);
  c1->WaitPrimitive("\n");
  fooApp.Run();
  return 0;
}

Note the inclusion of TApplication.h and the fooApp and fooApp.Run statements w.r.t to my
previous posting. After these changes. Can someone explain me why and is it to expected
that my previous posting has worked in an older version (honestly I can’t recapitulate with which it worked) and shoudl not work with recent versions ?

Cheers,

Roman