[PyQt] How to explicitly delete a QDialog when finished with it?

J Barchan jnbarchan at gmail.com
Thu Jul 12 13:12:35 BST 2018


On 12 July 2018 at 11:47, Florian Bruhin <me at the-compiler.org> wrote:

> Hey,
>
> On Thu, Jul 12, 2018 at 11:07:41AM +0100, J Barchan wrote:
> > Either way, if I do *not* specify
> ​​
> WA_DeleteOnClose I want to delete it
> > explicitly when I'm done reading its values or whatever.  In C++ I'd call
> > delete explicitly.  What should I do from PyQt/Python?  del??
> > .deleteLater()??
>
> I just use obj.deleteLater(). There's also sip.delete(obj) if you really
> need something gone immediately, but I almost never use that.
>
> Florian
>
> --
> https://www.qutebrowser.org | me at the-compiler.org (Mail/XMPP)
>    GPG: 916E B0C8 FD55 A072 | https://the-compiler.org/pubkey.asc
>          I love long mails! | https://email.is-not-s.ms/
>

​Thanks, Florian, I'll give deleteLater() a go and test.

​Let me ask you one other question.  I have a lot of these to deal with.  I
*suspect* that some of those which do not presently pass
​
WA_DeleteOnClose to the constructor do not actually access the dialog after
exec().  *All* my dialogs are derived from my own base class.  For
simplicity/clarity, I'd like to make my base class unconditionally
call super().__init__(parent,
Qt.WA_DeleteOnClose).  Then those callers which do *not* want auto-delete
can explicitly go self.setWindowFlags(self.windowFlags() &
~Qt.WA_DeleteOnClose) immediately *after* construction.  I think this will
give easiest default behaviour for my code.  The question is: is it OK to
switch off WA_DeleteOnClose after construction, or do you think there is
something which needs to know about this flag at construction-time only,
and afterward is too late to switch off??



-- 
Kindest,
Jonathan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180712/214595f5/attachment.html>


More information about the PyQt mailing list