[PyKDE] Issue with QDialog and lifetime

Toby Dickenson tdickenson at geminidataloggers.com
Thu May 26 13:51:26 BST 2005


On Thursday 26 May 2005 13:16, Giovanni Bajo wrote:
> Toby Dickenson <tdickenson at devmail.geminidataloggers.co.uk> wrote:
> 
> >> class QDialog2(QDialog):
> >>    def __init__(self, parent=0, name=0, modal=False, flags=0)
> >>        QDialog.__init__(self, parent, name, modal, flags |
> >> Qt.WDestructiveClose)
> 
> Actually, for my project, I'm better off with:
> 
> class QDialog2(QDialog):
>    def __init__(self, parent=0, name=0, modal=False, flags=0)
>         if modal:
>             flags |= Qt.WDestructiveClose
>        QDialog.__init__(self, parent, name, modal, flags)
> 
> Becuase modeless dialogs really need their ownership to be transferred to
> the parent.

modeless..... ahh...... completely different. You are right WDestructiveClose 
is the right tool for that job.

> > That works, but Im not sure I would recommend it. It leads to a bigger
> change
> > should you ever need to access the dialog after it has been closed. (or,
> more
> > likely, the value of a control widget on the dialog)
> 
> Notice that WDestructiveClose does not collect the Python object (of
> course). So you can easily do something like:
> 
> class MyDialog(QDialog2):
>      # bla bla
> 
>      def accept(self):
>          self.value = self.lineedit.text()
> 
> and then later access that string.

But then you need to have a different method to access the text before and 
after the close. I would rather:

    dlg = WhateverDlg(parent)
    dlg.lineedit.setText('foo')
    try:
        ok = dlg.exec_loop()
        if ok:
            print dlg.lineedit.text()
    finally:
        dlg.deleteLater()

plus you avoid the need for that boring code in accept()


-- 
Toby Dickenson

____________________

Important Notice:

This email and any attachments are confidential and may contain trade secrets or be legally privileged. If you have received this email in error you must not use, rely upon, disclose, copy or distribute the contents. Please reply to the sender so that proper delivery can be arranged and delete the email from your computer.
Gemini Data Loggers monitor incoming and outgoing email to ensure satisfactory customer service, maintain company security and prevent abuse of their email system. However, any views expressed in this email are not necessarily those of Gemini and Gemini cannot be held responsible for the content.
Gemini makes best efforts to ensure emails are virus free; however you are advised to carry out your own checks. Gemini does not accept responsibility for any damage resulting from email viruses.
____________________




More information about the PyQt mailing list