Cruz
23rd January 2009, 08:27
I'm trying to implement little close buttons on widgets, so that when the close button is pressed the widget is deleted. I connected the clicked() signal of the button to a slot of the widget.
void MyWidget::delete()
{
delete this;
}
This works really well too. The widget is deleted from its parent and from the layout and the layout is redone. Except that I get a warning:
QObject: Do not delete object, 'unnamed', during its event handler!
I suppose it's because the clicked() signal hasn't returned yet and the destructor of the button is called, since the parent widget is deleted. But then, how can a button ever delete itself on click?
void MyWidget::delete()
{
delete this;
}
This works really well too. The widget is deleted from its parent and from the layout and the layout is redone. Except that I get a warning:
QObject: Do not delete object, 'unnamed', during its event handler!
I suppose it's because the clicked() signal hasn't returned yet and the destructor of the button is called, since the parent widget is deleted. But then, how can a button ever delete itself on click?