Hi Rene,
>
> You have a huge mistake in TestMainFrame:: ProcessMessage with these
> statements
> case M_FILE_CLOSE:
> printf("deleteing the windows\n");
> delete this; //THIS WRONG
>
> You cannot delete an object while you are executing it. To close teh
> application simply replace the lines above by
> case M_FILE_CLOSE:
> printf("deleteing the windows\n");
> gApplication->Terminate();
>
OK,
but now how I use my destructor: TestMainFrame:: ~TestMainFrame()
because gApplication->Terminate();
terminates the application without going through the destructor !
Thank.
> see examples in $ROOTSYS/tutorials/gui/guitest.C
>
>
> Patrick Dupre wrote:
>> Hello,
>>
>> I took the following example on the root web site, but it crashes when I
>> make a test close file.
>> Why ?
>>
>>
>> #include <stdio.h>
>> #include <stdlib.h>
>> #include <error.h>
>> #include <string>
>> #include <iostream>
>>
>> #include <TROOT.h>
>> #include <TApplication.h>
>> #include <TVirtualX.h>
>> #include <TGListBox.h>
>> #include <TGClient.h>
>> #include <TGFrame.h>
>> #include <TGMenu.h>
>>
>> //using namespace std ;
>>
>> enum values
>> {M_FILE_OPEN, M_FILE_CLOSE, M_FILE_CANCEL, M_FILE_HELP_COMMAND };
>>
>> class TestMainFrame : public TGMainFrame
>> {
>> private:
>> TGPopupMenu *menuTest, *menuHelp, *menuCancel;
>> TGMenuBar *menubar;
>> public:
>> TestMainFrame(const TGWindow *pp, UInt_t w, UInt_t h);
>> ~TestMainFrame();
>>
>> Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
>> };
>>
>> TestMainFrame:: ~TestMainFrame()
>> {
>> printf("Deleting those objects ...wait a moment, please ...\n");
>> delete menuTest;
>> delete menuHelp;
>> delete menuCancel;
>> delete menubar;
>> }
>>
>> TestMainFrame::TestMainFrame(const TGWindow *pp, UInt_t w, UInt_t h) :
>> TGMainFrame(pp,w,h)
>> {
>>
>> menuTest = new TGPopupMenu(gClient->GetRoot());
>> menuTest->AddLabel("This is to open the window !!");
>> menuTest->AddEntry("&Close file ", M_FILE_CLOSE);
>>
>> menuCancel = new TGPopupMenu(gClient->GetRoot());
>> menuCancel->AddLabel("This is to cancel the window !!");
>> menuCancel->AddEntry("&cancel ",M_FILE_CANCEL);
>>
>> menuHelp = new TGPopupMenu(gClient->GetRoot());
>> menuHelp->AddEntry("&help ", M_FILE_HELP_COMMAND);
>>
>> menuHelp->Associate(this);
>> menuCancel->Associate(this);
>> menuTest->Associate(this);
>>
>> TGLayoutHints *barLayout = new TGLayoutHints(kLHintsTop|kLHintsLeft
>> |kLHintsExpandX,0,0,1,1);
>> TGLayoutHints *TestCancel = new
>> TGLayoutHints(kLHintsTop|kLHintsLeft,0,4,0,0);
>> TGLayoutHints *help = new TGLayoutHints(kLHintsTop|kLHintsRight);
>>
>> menubar = new TGMenuBar(this, 1,1, kHorizontalFrame);
>> menubar->AddPopup("&Test ", menuTest, TestCancel);
>> menubar->AddPopup("&Cancel ", menuCancel, TestCancel);
>> menubar->AddPopup("&Help ",menuHelp, help);
>> AddFrame(menubar, barLayout);
>>
>> //-----------------------------------------------------------------
>> MapSubwindows();
>> Resize(GetDefaultSize());
>> MapWindow();
>>
>> }
>>
>>
>> Bool_t TestMainFrame:: ProcessMessage(Long_t msg, Long_t parm1, Long_t
>> parm2)
>> {
>> switch(GET_MSG(msg))
>> {
>> case kC_COMMAND:
>> switch(GET_SUBMSG(msg))
>> {
>> case kCM_MENU:
>> switch(parm1)
>> {
>> case M_FILE_CLOSE:
>> printf("deleteing the windows\n");
>> delete this;
>> break;
>> default:
>> break;
>> }
>>
>> default:
>> break;
>> }
>> default:
>> break;
>> }
>> return kTRUE;
>> }
>>
>> using namespace std ;
>>
>> int main (int argc, char **argv) {
>> TApplication theApp ("App", &argc, argv) ;
>> TestMainFrame mainWindow (gClient -> GetRoot (), 800, 400) ;
>> cout << "Before the App.run\n" ;
>> theApp.Run () ;
>> cout << "After theApp.run\n" ;
>> return 0 ;
>> }
>>
>>
>
>
-- --- ========================================================================== Patrick DUPRÉ | | Department of Chemistry | | Phone: (44)-(0)-1904-434384 The University of York | | Fax: (44)-(0)-1904-432516 Heslington | | York YO10 5DD United Kingdom | | email: patrick.dupre_at_york.ac.uk ==========================================================================Received on Thu Oct 14 2010 - 11:42:45 CEST
This archive was generated by hypermail 2.2.0 : Thu Oct 14 2010 - 11:50:01 CEST