Re: TCanvas outside CINT?

Fons Rademakers (Fons.Rademakers@cern.ch)
Fri, 28 Feb 1997 17:03:52 +0100


Hi Martin,

to make a stand-alone program that uses the graphics of the ROOT
system, you must make first make an TApplication environment and
after the drawing call the TApplication::Run() method (which will
enter the X or Win32 eventloop and will popup the graphics canvas).

For example:

//==================================== main.C
#include "TROOT.h"
#include "TApplication.h"
#include "TCanvas.h"
#include "TLine.h"

extern void InitGui(); // loads the device dependent graphics system
VoidFuncPtr_t initfuncs[] = { InitGui, 0 };
int Error; // needed by Motif

TROOT root("martin", "Martin's ROOT", initfuncs);

void main(int argc, char **argv)
{
// First create application environment. If you replace TApplication
// by TRint (which inherits from TApplication) you will be able
// to execute CINT commands once in the eventloop (via Run()).
TApplication *theApp = new TApplication("App", &argc, argv);

// Do drawing and all everything else you want
TCanvas *c = new TCanvas("Picture", "The Alignment Geometry", 400,
400);
c->Show();

TLine *l = new TLine(0.1,0.2,0.5,0.9);
l->Draw();

c->Update(); // force primitive drawn after c->Show() to be drawn in
canvas

// Enter event loop
theApp->Run();

delete theApp;
}
//---------------------------------------

On HP-UX create executable using:

CC +a1 -w -g -c -I$ROOTSYS/include main.C
CC +a1 -g -o main main.o $ROOTSYS/lib/*.sl -lXm -lXt -lX11 -lPW -lm

Cheers, Fons.

Martin Woudstra wrote:
>
> Hello,
>
> Can I use TCanvas objects also directly in a C++ program, or does
> it only work in the CINT interpreter?
>
> The following command in my C++ code, which I compile with HP CC,
> doesn't create any canvas on the screen:
>
> TCanvas *Picture = new TCanvas("Picture", "Canvas of the Alignment
> Geometry", 400, 400);
>
> And the command gROOT->Reset() gives the following run-time error:
>
> *** Break *** segmentation violation
>
> ( 0) 0xc1859320 StackTrace__11TUnixSystemFv + 0x30
> [/localdisk/woudstra/root/lib/libUnix.sl]
> ( 1) 0xc1857c7c DispatchSignals__11TUnixSystemF8ESignals + 0x12c
> [/localdisk/woudstra/root/lib/libUnix.sl]
> ( 2) 0xc1856804 SigHandler__F8ESignals + 0x2c
> [/localdisk/woudstra/root/lib/libUnix.sl]
> ( 3) 0xc185adc4 sighandler__Fi + 0x5c
> [/localdisk/woudstra/root/lib/libUnix.sl]
> ( 4) 0xc01264d8 _sigreturn [/usr/lib/libc.1]
> ( 5) 0xc1e98560 G__destroy_upto + 0x50
> [/localdisk/woudstra/root/lib/libCint.sl]
> ( 6) 0xc1e984c4 G__scratch_globals_upto + 0x24
> [/localdisk/woudstra/root/lib/libCint.sl]
> ( 7) 0xc18e85e8 ResetGlobals__5TCintFv + 0x18
> [/localdisk/woudstra/root/lib/libRint.sl]
> ( 8) 0xc1fe80a4 Reset__5TROOTFPc + 0xc4
> [/localdisk/woudstra/root/lib/libBase.sl]
> ( 9) 0x00013420 Draw__9CGeometryFv + 0x3c [.//geofix]
> (10) 0x0000a9ec main + 0x370 [.//geofix]
> (11) 0xc0077abc _start + 0x8c [/usr/lib/libc.1]
> (12) 0x00007dc4 $START$ + 0x134 [.//geofix]
>
> Thanks,
>
> Martin.

-- 
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 7822601