Problem closing a TGMainFrame


I wrote a small code where I am using a class which inherits from TGMainFrame. In its destructor I have the following lines:

delete cCurrent; delete cFFT; delete cPreview; delete lineFrequency; delete boxWindow; Cleanup(); //DestroyWindow(); gSystem->ProcessEvents();

The five first lines are just deleting objects (line, canvas, box).

I have only one button in my GUI which executes a function and at its end calls this line:

So the destructor is really called, my canvas are deleted, however I have still my window, its does not want to disappear.

In fact I am creating my TApplication in another file like this:

After I have a loop with a cin to ask the operation and at one time I am creating my class and running my application like this:

[code]else if(ask == “process”)
//Ask for the folder
std::cout << “Folder: Raw/”;
std::string folder;
std::cin >> folder;

		Processor processor("Raw/"+folder);
		//Run the application

so when I am calling Terminate(0) the loop continues to run (what I want).

I tried to add DestroyWindow() in my destructor, so it is working, the window disappears but if I am creating a new instance of the class I got the following error:

Thank you,


Hi Pierre-Louis,

I don’t really see the goal of what you’re trying to do… But anyway, one solution would be to connect your button to TGMainFrame’s CloseWindow() method, and call gApplication->Terminate() from its destructor.
If it doesn’t help, then it would be more easy to post your code somewhere, so I can take a look and propose a working solution.

Cheers, Bertrand.

Yes it is maybe easier to post a small working code. So the files are:

  • the makefile (remove .txt)
  • Project.cpp is containing the main, and there is a loop to ask for the action (here process)
  • Processor.cpp and Processor.h, I put only the graphical part, and when I click on “Process” if I do not have the DestroyWindow line, the window is still on the screen… but with this line I have an error if the next action is still “process”…

Thank you,

Makefile.txt (214 Bytes)
Project.cpp (848 Bytes)
Processor.h (889 Bytes)
Processor.cpp (1.93 KB)


OK, thanks for the code. I must say it is a original (to not say weird) approach… :wink:
Anyway, could you try this way:

[code]//Destructor: leave it empty
Processor::~Processor() {}

//Save processed data and terminate
void Processor::saveProcessedData()
The call to DestroyWindow() will call the destructor and unregister the Window from X11.
And you will have to replace Processor processor("Raw/"+folder); by new Processor("Raw/"+folder); Otherwise the processor object will be deleted again when going out of scope…

Cheers, Bertrand.

Sorry for the late reply, thank you for the solution.

Best regards,