Re: Canvas is not shown.

From: Fons Rademakers (Fons.Rademakers@cern.ch)
Date: Wed Mar 04 1998 - 18:54:17 MET


Hi Jayoung,

   first concerning points 1) and 2). They crash because you have a
typo in the script:

TCanvas c1 = ...

should be

TCanvas *c1 = ...

like in your compiled program (in 3)). Once corrected they will
show the canvas and you can interact with it, i.e. you can use the
menu's in the menubar and the popup menu in the canvas works (click
right button in canvas).

In case 3 you don't see a canvas because before the system can
create and show them the program exits. To be able to show and
interact with a canvas you need to be in an eventloop that will
process the GUI events (X11 or Win32). You get into the eventloop
by calling TApplication::Run() (note, inside the ROOT cint interface
the Run() method handles the command processing. I.e. you are always
in the Run() method and whenever a script is finished the created
GUI components are displayed.

Now to make your program in point 3) work as expected, add the lines:

int main()
{
   TROOT ytrack("plot2","plot test");

   // Create application environment, needed for interactive apps.
   // Alternatively can create a TRint object, I which case you
   // get also command line input capability.
   TApplication theApp("App", 0, 0);

   TCanvas *c1 = new TCanvas("c1","Tracking of Incident Particle",
                             200,10,700,500);
   c1->Update();

   theApp.Run();    // will not return

   return 0;
}


For more detail see $ROOTSYS/test/hworld.cxx.

Cheers, Fons.




Jayoung Wu wrote:
> 
> Hi,
>   I do not understand why compiled version with ROOT lib does not show
> any Canvas while Cint version shows Canvas???
> The follwing was my trials:
> 
> 1. "inside" of ROOT's cint interface:
> 
> ================= my code "jayoung.C" is ============================
> {
>   gROOT->Reset();
> 
>   TCanvas c1 = new TCanvas("c1","Tracking of Incident Particle",
>                                   200,10,700,500);
>   c1->Modified();
>   c1->Update();
> }
> =======================================================================
> root [0] .x jayoung.C shows a Canvas. But it gives the following error
> ^^^^^^^^^^^^^^^^^^^^^                      message:
> Warning in <TCanvas::Copy>: copy not implemented yet
> 
>  *** Break *** segmentation violation
> 
> 2. "inside" of ROOT's cint interface:
> 
> ================= my code "jayoung.C" is ============================
> {
>   gROOT->Reset();
> 
>   TCanvas c1 = new TCanvas("c1","Tracking of Incident Particle",
>                                   200,10,700,500);
> //  c1->Modified();
> //  c1->Update();
> }
> =======================================================================
> root [0] .x jayoung.C shows a Canvas. But it gives the following warning
> ^^^^^^^^^^^^^^^^^^^^^                      message:
> Warning in <TCanvas::Copy>: copy not implemented yet
> 
> 3. "outside" of ROOT's cint interface: execute compiled program with ROOT
>     lib.  My version is "root_v0.9.OSF1.v3.2".
> 
> ================= my code "jayoung.C" is ============================
> #include <stdio.h>
> #include <math.h>
> 
> #include "TROOT.h"
> #include "TFile.h"
> #include "TTree.h"
> #include "TBranch.h"
> #include "TObject.h"
> #include "TH1.h"
> #include "TCanvas.h"
> 
> void main()
> {
>   TROOT ytrack("plot2","plot test");
> 
>   TCanvas *c1 = new TCanvas("c1","Tracking of Incident Particle",
>                                   200,10,700,500);
> 
> //  c1->Modified();
> //  c1->Update();
> }
> ====================================================================
> It is successfully comlied with ROOT lib (root_v0.9.OSF1.v3.2).
> But it does not show any canvas when it is executed.
> Also it does not complain anything at all.
> 
> ---
> Thanks a lot!
> Jayoung

-- 
Org:    CERN, European Laboratory for Particle Physics.
Mail:   1211 Geneve 23, Switzerland          Phone: +41 22 7679248
E-Mail: Fons.Rademakers@cern.ch              Fax:   +41 22 7677910



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:30 MET