When you make TstWidgetHolder::setParent(this)
you are delegating ownership (in other words, responsability to destruct) of the TestWidget
instance to this
. So, right before the object pointed to by this
is destructed, it tries to delete tst
, which is an static object... and that is what makes your application crash. Either you don't use setParent
or you should change TstWidgetHolder::setParent
to:
void TstWidgetHolder::setParent(QWidget* obj)
{
TstWidgetHolder::wobj = new TestWidget(obj);
}