How to destroy second window when closed
Solved
General and Desktop
-
hello,
I'm working on a new qt project, and I need to be sure to manage correctly the memory allocation and the resources. Just want to ask if someone can give me some suggestion about the way to correctly close a second window, opened from the main window, in particular I need to de-allocate the memory when window is closed.
Thanks for the support
Davide -
@davidesalvetti
there are multiple ways to achieve this.- you can set the parent of the secondary window to the mainwindow. And on the main window set the
Qt::WA_DeleteOnClose
widget attribute. Then the secondary window is closed automatically when the mainwindow is closed. - do it manually at any time by keeping a pointer to the secondary window and call
close()
on it - ...
- you can set the parent of the secondary window to the mainwindow. And on the main window set the
-
For modal dialogs you normally just allocate on the stack, and call the blocking
exec
(with a bit of caution)for any other sub window you can use
setAttribute(Qt::WA_DeleteOnClose);
-
thank you a lot for the fast reply! It works now.