I’m trying to do something fairly simple. Add labels to a frame and add that frame to
a canvas. Here’s my code…
//MyMainFrame.h
#include <TRootEmbeddedCanvas.h>
#include <TGFrame.h>
#include <TApplication.h>
#include <TGLabel.h>
class MyMainFrame : public TGMainFrame{
private:
TRootEmbeddedCanvas fECanvas;
TGHorizontalFrame fHFrame;
TGLabel* fNumberEntryLabel;
public:
MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
virtual ~MyMainFrame();
ClassDef(MyMainFrame,1);
};
//My MainFrame.cxx
#include “rootanalysis/MyMainFrame.h”
ClassImp(MyMainFrame);
MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h):TGMainFrame(p,w,h){
fECanvas = new TRootEmbeddedCanvas(“ECanvas”,this,200,200);
AddFrame(fECanvas, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,10,10,10,1));
fHFrame = new TGHorizontalFrame(fECanvas,200,40);
fNumberEntryLabel = new TGLabel(fHFrame,“No. Entries”);
fHFrame->AddFrame(fNumberEntryLabel, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY ,5,5,3,4));
AddFrame(fHFrame,new TGLayoutHints(kLHintsCenterX,2,2,2,2));
//Sets window name and shows the main frame
SetWindowName(“Simple Example”);
MapSubwindows();
Resize(GetDefaultSize());
MapWindow();
}
MyMainFrame::~MyMainFrame(){
delete fECanvas;
delete fNumberEntryLabel;
delete fHFrame;
}
This compiles just fine, but when I run it seg faults at AddFrame.
(gdb) where
#0 0x0318ecef in raise () from /lib/tls/libc.so.6
#1 0x031904f5 in abort () from /lib/tls/libc.so.6
#2 0x010a4cee in TUnixSystem::Abort () from /disk01/software/root/pro/lib/libCore.so
#3 0x010a352c in TUnixSystem::DispatchSignals () from /disk01/software/root/pro/lib/libCore.so
#4 0x010a21db in SigHandler () from /disk01/software/root/pro/lib/libCore.so
#5 0x010a7097 in sighandler () from /disk01/software/root/pro/lib/libCore.so
#6
#7 0x00000000 in ?? ()
#8 0x01b667e3 in TGCompositeFrame::AddFrame () from /disk01/software/root/pro/lib/libGui.so
#9 0x00c57789 in MyMainFrame (this=0xa84df80, p=0xa4b6998, w=200, h=220) at private/rootanalysis/MyMainFrame.cxx:14
I imagine I’m doing something that’s very obviously wrong, but I’ve been staring at this
for awhile and am running out of ideas. Any help or suggestions would be greatlly
appreciated.
Thanks,
Alex.