TGTextEditor CloseWindow() signal problem

Hello,

as my posts have caused some confusion in the past, here first a short version of my problem: :slight_smile:

Clicking the “x” at the window corner of a TGTextEditor emits a CloseWindow() signal, but closing via File->Exit menu or by pressing the exit button on the toolbar unfortunately doesn’t.

And now the details about what I’m trying to do with these signals, because maybe there is a better way.

In my gui application you can add some output to a TGTextEditor (fEditor) which will pop up when EditorWrite() is called. Since, this can be done repeatedly and I don’t want multiple editors to pop up, I have to monitor whether “fEditor” exists already or not. However, this is only working partially.

My approach - I am open for better ideas - relies on the TGTextEditor::CloseWindow() signal. When the signal is emitted I set fEditor = 0 and when I want to write to fEditor I check if( fEditor == 0 ). ( See below and also in the little test app attached to this post. EditorWrite() can be called via the histogram drop-down menu. )

void MyGui::EditorWrite(){
  if( fEditor == 0 ){
    fEditor = new TGTextEditor();
    fEditor->Connect(fEditor, "CloseWindow()", "MyGui", this, "EditorClosed()");
  }
  fEditor->AddText( new TGText("Added some text to the editor") );
}

void MyGui::EditorClosed(){
  std::cout << "Inside EditorClosed()" << std::endl;
  delete fEditor;
  fEditor = 0;
}

Like mentioned above, this works pretty well if I close the editor via the little “x” in the window corner - the CloseWindow() signal is emitted as confirmed by the “Inside EditorClosed()” message. Whenever I use the File->Exit menu or the toolbar exit button, there is no signal and thus no message and no reset of fEditor. The reason might be the variable “fExiting” in the TGTExtEditor::CloseWindow() source, maybe Bertrand knows.

Anyway, is there a way to work around that, e.g. like blocking the not working exit methods, so the editor can only be closed by the “x”? Or maybe something completely different?

Thanks
Greg
MyGui.tar.gz (1.3 KB)

I’m feeling a bit embarrassed now, but I just gave it a try with TQObject’s “Destroyed()” signal and that will do the job.

The ‘delete fEditor;’ has to be removed from the “EditorClosed()” method for it to work.

The question why it’s not working with “CloseWindow()” remains, of course, unanswered by this.

Hi Greg,

Glad to see you found a solution before I had time to reply :wink:
And the CloseWindow() signal is only emitted when the window is closed via the window manager, since we don’t have any other way to be notified when this happens…

Cheers, Bertrand.