double free or corruption (out) when closing a QDialog with the WA_DeleteOnClose attribute set
-
@JonB said in double free or corruption (out) when closing a QDialog with the WA_DeleteOnClose attribute set:
Do you perchance mean delete is not allowed on a stack variable?
Indeed, it was a typo.
-
@kshegunov
A "typo" is a misspelling, not a complete reversal of a comment's intention! :DAnd I agree it's about time somebody said you just must not delete a stack variable, period. [Whether
WA_DeleteOnClose
docs might mention that is what this does, and so should only be used on heap instances, is another matter. I was never clear just what exactlyWA_DeleteOnClose
did, though I used it. -
@kshegunov said in double free or corruption (out) when closing a QDialog with the WA_DeleteOnClose attribute set:
There's nothing sinister, the OP already provided the answer.
no matter what, telling a class to commit suicide is sinister in my books :P
-
@LRDPRDX yes, its exactly where my debugger stopped.
-
@JonB said in double free or corruption (out) when closing a QDialog with the WA_DeleteOnClose attribute set:
A "typo" is a misspelling, not a complete reversal of a comment's intention! :D
I added the comma after the fact, which introduced the missing negation, so *shrug* happens.
@J-Hilk said in double free or corruption (out) when closing a QDialog with the WA_DeleteOnClose attribute set:
no matter what, telling a class to commit suicide is sinister in my books :P
Your books are wrong. We are a free-haven! ;)
-
@kshegunov said in double free or corruption (out) when closing a QDialog with the WA_DeleteOnClose attribute set:
I added the comma
-
At the end of the QDialog:exec there are:
if (deleteOnClose) delete this; return res;
On Mac i got:
malloc: *** error for object 0x7ffeefbffa60: pointer being freed was not allocated
so it crashes at the delete instruction and never returns. -
@kshegunov said in double free or corruption (out) when closing a QDialog with the WA_DeleteOnClose attribute set:
You don't need to be a Qt developer to know this, and it has nothing to do with how you call the delete -- from the outside, from the inside (i.e. deleting this), through a custom event or without.
Agreed, but how do I know what the
Qt::WA_DeleteOnClose
actually does? One can guess it causes the call ofdelete
on the variable but that was just not enough to me to be sure (and obviously I was looking for an answer in the wrong place in the source code). Anyway, now I've got the answer. Thank you. -
kshegunov Moderatorsreplied to LRDPRDX on 8 Nov 2021, 13:09 last edited by kshegunov 11 Aug 2021, 13:16
@LRDPRDX said in double free or corruption (out) when closing a QDialog with the WA_DeleteOnClose attribute set:
Agreed, but how do I know what the Qt::WA_DeleteOnClose actually does?
If you feel the name doesn't give it up, or isn't clear enough, I'd've suggested looking up in the documentation:
https://doc.qt.io/qt-5/qt.html#WidgetAttribute-enumIt's sort of the point of having documentation - so you don't need to go browsing through the code, and thankfully Qt has the best one I've ever seen.
-
@kshegunov Yes, ofc, I read that. For some reason I interpret the word "delete" (when it's not formatted :) ) as a general way to destroy an object. -_-
-
In terminal, "double free or corruption (out)" message is printed after the destructor has been called.
Update: Sorry for bothering you. I was having similar issue. I saw your post in stackoverflow and then my problem solved when I allocated my QMainWindow object in heap instead of the stack.
Many thanks!