dlgProgress->setAttribute(Qt::WA_DeleteOnClose);
deletes the widget when it is closed. As you are calling dlgProgress->close();
, after this line the object it points to has been freed, and dlgProgress
is now a invalid pointer.
You need to set dlgProgress
to null after any call to close, or event better, use the signal Qobject::destroyed()
.
EDIT:
Qt::WA_DeleteOnClose
specify that the object will be deleted if a close event happens. Not exactly how much time it will take. For instance if they are using QObject::deleteLater()
, then the object is not deleted right away. Even if it is not the case , pieces of code like
A* a = new A;
a->dosomething();
delete a;
a->dosomething();
are undefined behavior. The second call to a->dosomething();
may crash (if you are lucky) or may not crash.