Delete widget
-
@mahd96 said in Delete widget:
what happens to child widgets when the parent is deleted?
The children are deleted too: https://doc.qt.io/qt-5/objecttrees.html
i have a crash in deleting a parent widget and i guess its because of some thing i didn't consider with children.
Try using
deleteLater()
instead ofdelete
.Also, use a debugger and look at the stack trace when it crashes.
-
@JKSH it's not working. there is some point that i got to.
for child that has pointer-like defenition(Qwidget *widget=new ...!) must use "this" keyword for initialzing them ( using setparent after creating object cause crash!)
child that are not pointer like must be added to a layout.(again setparent will cause crash!)these behavior seems odd to me!
-
@mahd96 said in Delete widget:
for child that has pointer-like defenition(Qwidget *widget=new ...!) must use "this" keyword for initialzing them ( using setparent after creating object cause crash!)
child that are not pointer like must be added to a layout.(again setparent will cause crash!)I don't really understand what you're trying to say. Can you show your code? How you're setting parent and how you're deleting?
"i think theres issue with Construction/Destruction Order of QObjects" - I would first check my own code before saying that there is something wrong in the framework (which can, of course, be the case!).
-
@mahd96 said in Delete widget:
@JKSH i think theres issue with Construction/Destruction Order of QObjects.
Read the link I gave you: https://doc.qt.io/qt-5/objecttrees.html