Hello,
I have made a gui program based on the tutorial gui/guitest.C.
In the main class TestMainFrame, I have declared a vector, vector peaks. I have a histogram in an embedded canvas that I have connected to processedEvents with:
gVirtualX->SetInputFocus(fEc1->GetContainer()->GetId());
c1->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "TestMainFrame",
fHpx, "ExecuteEvent(Int_t,Int_t,Int_t,TObject*)");
Where c1 is the canvas, fHpx is the plotted histogram and fEc1 is the embedded canvas. The function ExecuteEvent decides if the event is a keypress or not, and fills a vector with the X-axis location whenever the ‘p’ key is pressed. However, in the function below, it seems to think the vector has not been allocated or something and so crashes when I try to do, peaks.push_back(last_x) or gives me some giant value when I call peak.size(). The function is:
void TestMainFrame::ExecuteEvent(Int_t event, Int_t px, Int_t py, TObject *sel){
// some magic to get the coordinates...
float x = gPad->AbsPixeltoX(px);
float y = gPad->AbsPixeltoY(py);
x = gPad->PadtoX(x);
y = gPad->PadtoY(y);
static float last_x;
static float last_y;
if(event!=kKeyPress)
{
last_x=x;
last_y=y;
//return;
}
if(event == kKeyPress){
switch(px){
case 'b':
cout << "background" << endl;
break;
case 'p':
cout << "Peak Select" << endl;
peaks.push_back(last_x);
cout << last_x << " " << last_y << " " << peaks.size() << endl;
break;
};
}
}
The vector is declared as a private member of the TestMainFrame class, while this function is a public member. Following the convention of the guitest.C tutorial I based most things on. If I ask any of my other functions handing signal/slots, like button presses in the gui or menu actions, they all know the peak vector exists and can fill and give me the correct size, but there is something with this particular function that it won’t. Since it is handling the keyboard presses and runs on the ProcessedEvents() I wasn’t sure if they were related.
This is the output when this function is run and I press ‘p’:
libc++abi.dylib: terminating with uncaught exception of type std::bad_alloc: std::bad_alloc
The code is attached,
guitest.C (28.0 KB)
Thanks,
_ROOT Version:6.14.06
_Platform:MacOSX 10.14.2
Compiler: Not Provided