Hi ROOTers
I am trying to implement a class with the following declarations:
class APIanalyzer : public TGMainFrame {
private:
TRootEmbeddedCanvas *fEcanvas;
TGStatusBar *fStatusBar;
char* myFavouriteText;
int totalCanvas;
public:
//Other functions...
APIanalyzer::APIanalyzer(const TGWindow *p,UInt_t w,UInt_t h,int argc, char **argv)
: TGMainFrame(p,w,h),canvasCounter(0) {
fEcanvas = new TRootEmbeddedCanvas ("Ecanvas",this,1000,800);
int parts[]={60,20,20};
fStatusBar = new TGStatusBar(this,50,10,kHorizontalFrame);
fStatusBar->SetParts(parts,sizeof(parts)/sizeof(parts[0]));
this->AddFrame(fStatusBar,new TGLayoutHints(kLHintsBottom | kLHintsLeft | kLHintsExpandX,0,0,2,0));
fStatusBar->SetText("This works here....",1);
// Sets window name and shows the main frame
this->SetWindowName("API Pre-Analysis Plots");
this->MapSubwindows();
this->Resize(GetDefaultSize());
this->MapWindow();
this->Connect("CloseWindow()", "APIanalyzer", this, "DoExit()");
this->DontCallClose();
ProcessData();
}
void GetCoordinates(){
//status bar has been divided into three parts
fStatusBar->SetText("My test",0);
fStatusBar->SetText(myFavouriteText,2);
}
void ProcessData(){
TCanvas *c = fEcanvas->GetCanvas();
c->Divide(1,totalCanvas);
for(int i=0;i<totalCanvas;i++){
TPad* p1=(TPad *)(c->cd(i+1));
gPad->AddExec("dynamic",
Form("((APIanalyzer*)0x%x)->GetCoordinates()",this));
}
}
int main(int argc, char **argv){
TApplication theApp("APIanalyzer", &argc, argv);
APIanalyzer mainWindow(gClient->GetRoot(),600,500,theApp.Argc(), theApp.Argv());
//APIanalyzer subWindow(gClient->GetRoot(),600,500,theApp.Argc(), theApp.Argv());
theApp.Run();
return 0;
}
As you see, I am assigning a member function of APIanalyzer to each pad in the canvas via gPad->AddExec(). Now I get the following error:
[quote]
*** Break *** segmentation violation
Attaching to program: /proc/30876/exe, process 30876
[Thread debugging using libthread_db enabled]
[New Thread 0x7f80cb1516f0 (LWP 30876)]
done.
0x00007f80c53ee4a5 in waitpid () from /lib/libc.so.6
error detected on stdin
The program is running. Quit anyway (and detach it)? (y or n) [answered Y; input not from terminal]
Detaching from program: /proc/30876/exe, process 30876[/quote]
The error happens because I am trying accessing the fStatusBar object after I have done the linkage of GetCoordinates() function to each pad. In general, I find out that if I defined the following inside my get coordinates, I also get a segmentation fault:
It seems that I do not have access to my member variables/objects/functions. Is there a way I could get over this problem? I am thinking maybe the best way to go around this problem is by defining signals and slots. I am still curious to know If I could make my code work by rewriting it in another way (maybe a proper way?).
Thank you,
Kris