TGMainFrame problem with close button


I experienced a strange behaviour with the TGMainFrame close button:

  • I create a class derived from TGMainFrame
  • I connect the “close button” from the window to a custom class function (I named it CloseButtonClicked() ) and I call the DontCallClose() function to prevent closing the window

Up to here, the behaviour seems ok: if the CloseButtonClicked() function does nothing, my window is not closed, and if I delete it (with DeleteWindow() function for example), this works.

Now I would like to request a closing confirmation in the CloseButtonClicked() function.
I defined a simple dialog, based on the TGTransientFrame class, with 2 buttons (namely “OK” and 'Cancel") for this confirmation, and depending on the selected answer, I want to close or not my
main window.

The situation is the following:

  • This simple dialog works fine and I retrieve a 0/1 value, depending on the button.
  • I test this value (in the CloseButtonClicked() function) - this is ok
  • Depending on the result, I call or not the closing function

But the main window is always closed, independently of the confirmation result.
I completely removed the closing function call, then doing nothing after the confirmation dialog, and the main window is closed anyway.

Could it be that creating (and closing) the dialog (TGTransientFrame) changes the behaviour for the main window ?

Thanks for any help.

Please read tips for efficient and successful posting and posting code

ROOT Version: 6.xx
Platform: CentOS7
Compiler: g++

Can you provide a simple reproducer, to see how you do that in reality?

Since it is in a larger set of code, I will try to extract a minimal code.
I need a bit of time for that.

Before I can provide it, here are the main code elements.
In particular, the AGPage::CloseButtonClicked ( ) function, with detailed comments.

// header for the main application
class AGPage : public TGMainFrame
  virtual void CloseButtonClicked ( );
// code for the main application

AGPage::AGPage ()
      : TGMainFrame ( gClient->GetRoot(), 100, 100 ),
  Connect ("CloseWindow()", "AGPage", this, "CloseButtonClicked()");


void AGPage::CloseButtonClicked ( )
  cout << "AGPage::CloseButtonClicked ( )" << endl;

//  PART 1: confirmation

  // delete confirmation dialog:
  //      the RGMessageRequester is a (personal) class that inherits
  //      from TGTransientFrame
  //      the dialog is closed by any button (OK or Cancel), and depending
  //      on the button, the req argument receives 0 or 1
  int req = 0;
  new RGMessageRequester ( gClient->GetRoot(), this, req,
                           "Warning", "\n  Really delete the page ?  \n\n",
                           kTextLeft, "  0K  |Cancel" );

  // I check the returned value is correct
  cout << "AGPage::CloseButtonClicked ( ) req=" << req << endl;

//  PART 2: close or not
  if ( req != 0 )  // OK button selected
      gClient->WaitForUnmap ( this );

//    - removing (commenting) all function code: the window does not close (as expected)
//    - removing only PART 2, the main window closes anyway !!!!

OK, thanks, I’ll check and try to figure out what’s wrong

I made a small code reproducing the problem:

  • a main program calling a test main window: class TestMain
  • when clicking the TestMain close button, open a simple dialog (class MyDialog) for confirmation


  • TestClass.hh and TestClass.cpp: header and code for the classes TestMain and MyDialog
  • TestProg.cxx: the main program
  • TestLib_linkdef.h: for the ROOT dictionary
  • makefile

The makefile creates the ROOT dictionary and the test library (TestLib) for the test classes, and compiles and link the executable program.

mainframe_2022-05-20_12h10.tgz (2.7 KB)

OK, so in your example, let’s try the following:
In TestProg.cxx, replace:

  gClient->WaitForUnmap ( testMain );


  gClient->WaitFor( testMain );

and in TestClass.cpp, replace:

    gClient->WaitForUnmap ( this );

by (simply):


And let me know

It works fine with the changes you suggested.

But I do not understand how it changes the deletion of the main window:

  • the 2nd change is in the dialog class
  • the first change is about the main window, but it is unmapped (in this case) only when closed, which should not be the case…

Sounds really not clear to me…

Anyway, thanks a lot, I will apply this to my full code.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.