Problem with closing window

Hi

First, I would say that I have read tutorials, users guide and I have been looking answer for this problem in google.
I write program in C++ which have few window: main of course, options (dialog), advanced actions etc.My problem for most of use is probable ridiculous:
I can’t create window which don’t crash when I close it by button, (x) - top-right corner, or ctrl+f4.
I have followed through the guitest.C (which is in tutorial) and I try this methords in meny variants:

fMain->Connect(“CloseWindow()”, “Test”, this, “CloseWindow()”);
fMain->DontCallClose();
fMain->SetCleanup(kDeepCleanup);

in CloseWindow(): delete this

In destructor:

  • list od delete X - where X is widget
  • empty
  • DeleteWindow();

and always are problems.

When destructor look like this:

GuiOptions::~GuiOptions() { printf("DESTRUCTOR\n"); fMain->DeleteWindow(); }

I can see:

[code][dirdival@pld okna]$ ./test2K2Kgui
HandleMenu
MENU_OPTIONS
CLOSE WINDOW
DESTRUCTOR
Error in : BadWindow (invalid Window parameter) (TGTextEntry XID: 31457422, XREQ: 61)
TGTextEntry: 31457422
TGVButtonGroup: 31457417

*** Break *** segmentation violation
Using host libthread_db library “/lib/tls/libthread_db.so.1”.
Attaching to program: /proc/14252/exe, process 14252
[dirdival@pld okna]$ [/code]

or this:

[code][dirdival@pld okna]$ ./test2K2Kgui
HandleMenu
MENU_OPTIONS
CLOSE WINDOW

*** Break *** segmentation violation
Using host libthread_db library “/lib/tls/libthread_db.so.1”.
Attaching to program: /proc/14358/exe, process 14358
0xffffe410 in __kernel_vsyscall ()
#1 0xb59226b3 in waitpid () from /lib/tls/libc.so.6
#2 0xb58cf7e2 in ?? () from /lib/tls/libc.so.6
#3 0xb59c089f in system () from /lib/tls/libpthread.so.0
#4 0xb7aad1af in TUnixSystem::Exec () from /lib/libCore.so
#5 0xb7aad673 in TUnixSystem::StackTrace () from /lib/libCore.so
#6 0xb7aaafdc in TUnixSystem::DispatchSignals () from /lib/libCore.so
#7 0xb7aa8b58 in SigHandler () from /lib/libCore.so

#27 0xb5c72dfe in TGMenuBar::HandleButton () from /lib/libGui.so
#28 0xb5c237f3 in TGFrame::HandleEvent () from /lib/libGui.so
#29 0xb5be8eb4 in TGClient::HandleEvent () from /lib/libGui.so
#30 0xb5be8b37 in TGClient::ProcessOneEvent () from /lib/libGui.so
#31 0xb5be8c38 in TGClient::HandleInput () from /lib/libGui.so
#32 0xb5be70e2 in TGInputHandler::Notify () from /lib/libGui.so
#33 0xb7aaa6af in TUnixSystem::DispatchOneEvent () from /lib/libCore.so
#34 0xb7a245b0 in TSystem::InnerLoop () from /lib/libCore.so
#35 0xb7a243ab in TSystem::Run () from /lib/libCore.so
#36 0xb79c1407 in TApplication::Run () from /lib/libCore.so
#37 0x08064cd3 in main ()
The program is running. Quit anyway (and detach it)? (y or n) [answered Y; input not from terminal]
Detaching from program: /proc/14358/exe, process 14358
Error in : BadWindow (invalid Window parameter) (TGTextEntry XID: 41943182, XREQ: 61)
TGTextEntry: 41943182
TGVButtonGroup: 41943177

*** Break *** segmentation violation
Using host libthread_db library “/lib/tls/libthread_db.so.1”.
Attaching to program: /proc/14358/exe, process 14358[/code]

When destructor is empty:

When I clicked Close nothing is happend - destructor is called but window is still open. When I clicked second time I see:

[code] *** Break *** segmentation violation
Using host libthread_db library “/lib/tls/libthread_db.so.1”.
Attaching to program: /proc/14529/exe, process 14529
0xffffe410 in __kernel_vsyscall ()
#1 0xb591d6b3 in waitpid () from /lib/tls/libc.so.6
#2 0xb58ca7e2 in ?? () from /lib/tls/libc.so.6
#3 0xb59bb89f in system () from /lib/tls/libpthread.so.0
#4 0xb7aa81af in TUnixSystem::Exec () from /lib/libCore.so
#5 0xb7aa8673 in TUnixSystem::StackTrace () from /lib/libCore.so
#6 0xb7aa5fdc in TUnixSystem::DispatchSignals () from /lib/libCore.so
#7 0xb7aa3b58 in SigHandler () from /lib/libCore.so
#8 0xb7aab8fe in sighandler () from /lib/libCore.so
#9
#10 0x0805502a in G__Dictionary_380_0_27 ()

#17 0xb5bc7aa6 in TGButton::EmitSignals () from /lib/libGui.so
#18 0xb5bc771d in TGButton::SetState () from /lib/libGui.so
#19 0xb5bc790a in TGButton::HandleButton () from /lib/libGui.so
#20 0xb5c1e7f3 in TGFrame::HandleEvent () from /lib/libGui.so
#21 0xb5be4130 in TGClient::HandleMaskEvent () from /lib/libGui.so
#22 0xb5be3b5e in TGClient::ProcessOneEvent () from /lib/libGui.so
#23 0xb5be3c38 in TGClient::HandleInput () from /lib/libGui.so
#24 0xb5be20e2 in TGInputHandler::Notify () from /lib/libGui.so
#25 0xb7aa56af in TUnixSystem::DispatchOneEvent () from /lib/libCore.so
#26 0xb7a1f5fd in TSystem::ProcessEvents () from /lib/libCore.so

The program is running. Quit anyway (and detach it)? (y or n) [answered Y; input not from terminal]
Detaching from program: /proc/14529/exe, process 14529
[/code]

I am exhausted, I have no idea how do it properly. What I do wrong?
Has anybody have simple code in C++ with good closing windows and can show it?

I add to post snipped of my code (okna.tar.gz). Window ,options’’ from menu always crash.

Linux PLD
ROOT Version 5.20/00
gcc version 3.3.6 (PLD Linux)

Regards
Krzysztof

PS.
Sorry for my english
okna.tar.gz (4.04 KB)

Hi

I solved this problem.

For posterity:

Every class destructor look normal: lists of thinks to delete.
Method CLoseWindow() have to look like this:

void GuiOptions::CloseWindow() { printf("GuiOptions: CloseWindow()\n"); DeleteWindow(); }

DeleteWindow call destructor. It works good in class inherited from TGTransientFrame, but not work in class inherited from TGMainFrame. Then we have use this:

void Test2k2Gui::CloseWindow() { gApplication->Terminate(0); }
I known it’s not best solution of this problem ,but it works.
I add example code with makefile (Linux).

I have seen first time example code in tutorial with mistakes. You should feel shame.

Regards,
Krzysztof
okna.tar.gz (4.73 KB)