How to close a TGInputDialog

Good afternoon!

I am working with a function that calls ROOT’sTGInputDialog widget and displays it. Now, whenever there is no input or the cancel button is pressed, I would like the TGInputDialog to close again.

new TGInputDialog(gClient->GetRoot(), GetMainFrame(),"Enter file path:",filepath, filepath); if (strcmp(filepath, "") == 0) { delete this; } // if else { //here i put code for saving a histogram } // else

Now, I get a segmentation violation when I run my macro in ROOT, apparently caused by the delete statement. However, I do not see why this is causing trouble. Can anyone help? Any help or suggestions are most welcome.


Well, first of all, I don’t understand what you mean by

[quote]I would like the TGInputDialog to close again.[/quote]if it is already closed, you cannot close it again…

Then I’m afraid there is nothing we can do with so little information anyway…
For example, which class “this” is refering to?
Could you post a running macro showing what you are trying to do and showing the problem?

Cheers, Bertrand.

Sorry for my poor description. I will try to make it more clear. The TGInputDialog widget is used for a graphical user interface that consists mostly of buttons and other widgets. They are all defined in a class like this.

[code]class NameClass:public TGMainFrame{
//widgets, histograms, variables
TGButton *fSaveButton;

//constructor, destructor, functions
void SaveIt();
} // NameClass[/code]

Now, I connect my fSaveButton to my slot SaveIt() whenever it signals Clicked(). The SaveIt() void contains nothing more than the code I put in my first message. It should create a new TGInputDialog object. The ‘this’ pointer should be referring to my class.

OK, this is slightly better.

So the problem comes from “delete this”. Never call “delete this” from a TGMainFrame (you must use its CloseWindow() method), or from a TQObject when executing a slot method (you’re deleting the object while using it…)

Cheers, Bertrand.