Dear experts
I want to make a GUI which after I click a button it process something and then clean up everything on the main frame, then add new things on it.
Here is part of code:
EventDisplay::EventDisplay() {
// Create main frame
mainFrame = new TGMainFrame(gClient->GetRoot(), 800, 600);
// Add label
TGLabel* label = new TGLabel(mainFrame, "Please select number of entries that you want to preprocess for T0 and ADC pedestal value");
mainFrame->AddFrame(label, new TGLayoutHints(kLHintsCenterX, 5, 5, 10, 10));
// Add number entry
preNumEventEntry = new TGNumberEntry(mainFrame, 0, 9, -1, TGNumberFormat::kNESInteger);
mainFrame->AddFrame(preNumEventEntry, new TGLayoutHints(kLHintsCenterX, 5, 5, 10, 10));
// Add process button
processButton = new TGTextButton(mainFrame, "&Process");
processButton->Connect("Clicked()", "EventDisplay", this, "Preprocess()");
mainFrame->AddFrame(processButton, new TGLayoutHints(kLHintsCenterX, 5, 5, 10, 10));
mainFrame->SetWindowName("Preprocess Entries");
mainFrame->MapSubwindows();
mainFrame->Resize(mainFrame->GetDefaultSize());
mainFrame->MapWindow();
}
void EventDisplay::Preprocess() {
int number = preNumEventEntry->GetIntNumber();
std::cout << "Processing " << number << " entries..." << std::endl;
mainFrame->Cleanup();
// Call SetupDisplay to create new elements
SetupDisplay();
}
void EventDisplay::SetupDisplay() {
// Create embedded canvas
embeddedCanvas = new TRootEmbeddedCanvas("embeddedCanvas", mainFrame, 800, 400);
mainFrame->AddFrame(embeddedCanvas, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
canvas = embeddedCanvas->GetCanvas();
// Set new canvas size
canvas->SetCanvasSize(800, 600);
// Set window name and map subwindows, main window
mainFrame->SetWindowName("Event Display");
mainFrame->MapSubwindows();
mainFrame->Resize(mainFrame->GetDefaultSize());
mainFrame->MapWindow();
}
I found that when I add the line mainFrame->Cleanup();
it give the seg fault when I click the button:
*** Break *** segmentation violation
[/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)
[/Users/siyuan/Physics/root/install/lib/libGui.so] TGButton::EmitSignals(bool) (no debug info)
[/Users/siyuan/Physics/root/install/lib/libGui.so] TGButton::HandleButton(Event_t*) (no debug info)
[/Users/siyuan/Physics/root/install/lib/libGui.so] TGFrame::HandleEvent(Event_t*) (no debug info)
[/Users/siyuan/Physics/root/install/lib/libGui.so] TGClient::HandleEvent(Event_t*) (no debug info)
[/Users/siyuan/Physics/root/install/lib/libGui.so] TGClient::ProcessOneEvent() (no debug info)
[/Users/siyuan/Physics/root/install/lib/libGui.so] TGInputHandler::Notify() (no debug info)
[/Users/siyuan/Physics/root/install/lib/libCore.so] TMacOSXSystem::DispatchOneEvent(bool) (no debug info)
[/Users/siyuan/Physics/root/install/lib/libCore.so] TSystem::InnerLoop() (no debug info)
[/Users/siyuan/Physics/root/install/lib/libCore.so] TSystem::Run() (no debug info)
[/Users/siyuan/Physics/root/install/lib/libCore.so] TApplication::Run(bool) (no debug info)
[/Users/siyuan/Physics/comet/crt/ana/EventDisplay/build/EventDisplay] main (no debug info)
[/usr/lib/dyld] start (no debug info)
What did I do wrong?