[PyKDE] Deallocating multiple non-modal Dialogs from the same class

Phil Thompson phil at riverbankcomputing.co.uk
Wed Jul 13 08:32:33 BST 2005

> Hi, I have a problem. I have a python dialog class derived from
> QDialog that must be instanced many times and be showed in a
> non-modal way. I discovered that I need to set the parent of the
> instances to the main window because if I set it to None the
> dialog shows and returns inmediately from his exec_loop().
> This is working ok, but the problem is that I think the instances are
> never deallocated, so the application will leak memory. By what I know
> about PyQT design, they aren't deallocated because a parent is set,
> so they will be alive until the parent dies. But the parent in this
> case is the application main window, and I can't set the parent to
> None because the problem explained before. Also, I cant make the class
> singleton because multiple instances of the dialog must be showed at
> the same time with different data.
> So, what I can do to instantiate multiple dialogs (at the same time)
> from the main window _and_ then make sure that are deallocated?
> Note, I exit from the dialogs with a done(x) triggered by a dialog
> button clicked() signal.
> (If somebody needs an example script in addition to this description
> of the problem, please tell me and I will post it).

This has been discussed recently on the mailing list - including
workarounds. Before I make a decision on a possible change of behaviour...

1. Why do you say "non-modal" and then use exec_loop() (which enforces

2. How do you keep track of the multiple instances of the dialog? Do you
keep an explicit reference (eg. save the dialog in a Python list of them)?
Or do you walk the main window's tree of children?


More information about the PyQt mailing list