Deleting object with a signal


I am trying to delete an object in using a signal.
But the object to be deleted is at the origin of the signal,
and I get an error message: TGButton::EmitSignals(bool) at the end of the execution.

To be more specific, I have a list of “Label” containing each one TGTextButton.
The purpose of the TGTextButton is to delete this “Label”, i.e., to delete its own container.

I attach an example of the code I try to run, with a Makefile.
In the DeleteLines function, removing the frame gives me the correct behaviour (the label disappears).
But I lost access to the real object, and have potential memory leaks.
But really deleting the frame (by delete), gives me the error mentioned above.
I tried to disconnect signals at different places, but it seems it is too late already…

I understand that something may be wrong in the way it is implemented.
This is maybe not possible at all.
Could you suggest to me an other way to design the code in this case ?

test_delete_button.tar (20 KB)

Hi Michael,

I don’t really understand what you’re trying to do, but you cannot delete an object emitting a signal from within a slot connected to it, it obviously gives a violation.
You can use any other method (setting a flag to remember the user pressed a button, use a single shot timer, …) but don’t try to delete an object while being used…

Cheers, Bertrand.

Hi Bertrand,

Thanks for the fast answer.
It seems reasonnable that it is not possible.

I guess than even with a flag, I would need a sort of timer to check the flag has been set and delete the object later on.
I will have a test with a shot timer, or redesign the GUI to select differently the object to delete.