[PySide] Form dialog subclassing QDialog

Philip Starkey philip.starkey at monash.edu
Mon Mar 3 13:15:34 CET 2014


Matthew Woehlke <mw_triad <at> users.sourceforge.net> writes:

> 
> On 2014-02-28 15:48, Jérôme wrote:
> > I wrongly assumed the dialog was destroyed at the end of the execution 
of its
> > exec_() method, and therefore it was too late to get its values.
> 
> Ah... nope, just hidden . In fact you can call show() or even exec_() 
> again if you like (on the same dialog). It's not destroyed until it goes 
> out of scope, same as most classes.
> 


I just want to add to this: if you have specified a parent widget when 
instantiating the QDialog, it is not destroyed until the parent widget is 
destroyed. If you set the parent widget to be your main window (which is 
likely to never be destroyed for the life of the program), and create a new 
QDialog on a button click, you will find your program leaks memory (because 
Qt is holding an internal reference to the QDialog, even though it has gone 
out of scope in Python).

It is best to call dialog.deleteLater() once you do not wish to access the 
dialog anymore.

Of course, if you plan to hide/show the same dialog many times, you don't 
have to do this, but in that case you would also be keeping a Python 
reference to the dialog around.

In general, to avoid memory usage growing in your program, call 
dialog.deleteLater() (once finished) if you don't plan to hold onto a Python 
reference to the dialog!




More information about the PySide mailing list