Given the following fragments of code :
class MyDialog : public QDialog
{
...
};
MyDialog::~MyDialog()
{
qInfo() << "~MyDialog()";
}
and
// scope begins
MyDialog d;
d.setAttribute( WA_DeleteOnClose, true );
int result = d.exec();
qInfo() << "After exec";
// scope ends
I get the following output
~MyDialog()
double free or corruption (out)
Aborted (core dumped)
Without d.setAttribute( WA_DeleteOnClose, true );
everything is fine and expected.
NOTE : I know that there is no need to use the delete on close in this case as the dialog deletes when leaving the scope. I also don't need for a "better solution" etc (I've read a lot of posts on SO and Qt Centre Forum with these irrelevant answers). The question is Why the error occurs at the first time the ~QDialog()
is called ? And maybe Am I right that the error occurs at the first time the ~QDialog()
is called?
delete this
happens before the caller does unwinds its stack. So that explains why it crashes, although not really in~QDialog
but more inoperator delete
. But IIRC GCC tends to inline the latter into the former. – Faille