Opening/closing TGTransientFrame in compiled code

Hello,

In guitest.C, the transientframe child class TestMsgBox has a member TGTransientFrame* fMain, to which it assigns:

Suppose I reproduce the architecture of guitest.C but in compiled code, so that I have a main block which instantiates an object of class Main_GUI: public TGMainFrame, which has a member object of class Transient_GUI : public TGTransientFrame, which has a member fMain just like TestMsgBox.

Now, if I open the transient frame and then hit its close button (implemented identically to the method used in guitest.c), the first time the button is clicked nothing happens, and the second time I get a segmentation fault.

I also noticed that if one changes two things, the problems go away:

  1. In the constructor of the TGTransientFrame inheritor, insert a call to the TGTransientFrame() constructor in the initialization list of the TGTransientFrame-derived object, then have

inside the constructor instead of the

2)Change ‘delete this;’ to ‘DeleteWindow();’ in the the CloseWindow method if the TestMsgBox-like class

Then, I can open and close the transient frame as I desire without segmentation fault.

Is this the right way to have a working, closable TGTransientFrame-derived gui element in standalone code? Is it documented as such somewhere in the users manual or tutorials? And if not can it be?

Or, is there some other thing I could be getting wrong that’s causing me to have to modify these two things when optimally one shouldn’t have to? I will produce a minimal reproduction of the error if you think it would be helpful.

Thanks,
Joe

Hi Joe,

If you want to see a compiled version of guitest.C, it is $ROOTSYS/test/guitest.cxx. You will see several examples of classes inheriting from TGTransientFrame.
And if you still have problems, feel free to post a small running piece of code showing what you’re trying to achieve.

Cheers, Bertrand.

Dear Bertrand,

This is exactly what I was looking for but didn’t see. I feel silly, thanks.

Joe

You’re welcome. And you can also look for classes inheriting from TGTransientFrame in the subdirectories of $ROOTSYS/gui/

Cheers, Bertrand.