Hi Brett, it is important that you connect a function to the TGMainFrame CloseWindow() signal in which you delete the frame and all other widgets. The default TGMainFrame::CloseWindow() just closes the TGMainFrame (i.e. destroys the associated X11 window, but does not delete the TGMainFrame object). See modified example below (note, don't do as in this example but use a proper class to contain fFrame and fButton): // -- dork.C TGMainFrame *gFrame; TGButton *gButton; void MyCloseWindow() { printf("MyCloseWindow()\n"); delete gButton; delete gFrame; } void dork () { cerr << "Dork!\n"; TGMainFrame* fFrame = new TGMainFrame(gClient->GetRoot(),500U,500U); fFrame->Connect("CloseWindow()", 0, 0, "MyCloseWindow()"); TGButton* fButton = new TGTextButton(fFrame,"Die",0); fButton->Connect("Clicked()","TGMainFrame",fFrame,"SendCloseMessage()"); TGLayoutHints* loh = new TGLayoutHints(kLHintsTop | kLHintsLeft); fFrame->AddFrame(fButton,loh); fFrame->Layout(); fFrame->MapSubwindows(); fFrame->Resize(fFrame->GetDefaultSize()); fFrame->MapWindow(); cerr << "Frame at: " << fFrame << endl; gFrame = fFrame; gButton = fButton; } In this case it also works as expected when closing the window via the Window Close button in Window Manager decoration. Cheers, Fons. PS: On Wednesday 17 October 2001 20:48, Brett Viren wrote: > Hi again. More info: > > Here is a short example > > void dorktest () > { > cerr << "Dork!\n"; > > TGMainFrame* fFrame = new TGMainFrame(gClient->GetRoot(),500U,500U); > TGButton* fButton = new TGTextButton(fFrame,"Die",0); > > fButton->Connect("Clicked()","TGMainFrame",fFrame,"SendCloseMessage()"); > TGLayoutHints* loh = new TGLayoutHints(kLHintsTop | kLHintsLeft); > fFrame->AddFrame(fButton,loh); > fFrame->Layout(); > fFrame->MapSubwindows(); > fFrame->Resize(fFrame->GetDefaultSize()); > fFrame->MapWindow(); > cerr << "Frame at: " << fFrame << endl; > } > > Run it like: > root [0] gObjectTable->SetObjectStat(true) > root [1] gObjectTable->Print(); > ... > [ no TGMainFrame or TGButtons ... ] > root [2] .x test/dorktest.C > Dork! > Frame at: 0x86d3b78 > root [3] gObjectTable->Print(); > ... > TGMainFrame 1 1 84 84 > 84 TGTextButton 1 1 144 144 > 144 ... > [ now, click button, Frame goes away ] > root [4] gObjectTable->Print(); > ... > TGMainFrame 1 1 84 84 > 84 TGTextButton 1 1 144 144 > 144 ... > > > So, what is the correct way to assure the Frame and Button get deleted? > > -Brett. -- Org: CERN, European Laboratory for Particle Physics. Mail: 1211 Geneve 23, Switzerland E-Mail: Fons.Rademakers@cern.ch Phone: +41 22 7679248 WWW: http://root.cern.ch/~rdm/ Fax: +41 22 7679480
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:03 MET