<div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div><div><br style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><blockquote>I want to close a Qdialog during its initialisation i.e. inside def<br>
__init__. I do some computing during the initialisation of a dialog.<br>
if they don't return a particular value i wish to close the dialog<br>
inside the init statement is it possible or is there a way i can achieve it.<br></blockquote>
One way would be to raise an exception inside __init__().<br><br></div><div>class myOddDialog(QDialog):<br></div> def __init__(parent):<br></div> if something_is_wrong :<br></div> raise ValueError<br><br></div>And then create it inside a try:<br><br></div> try:<br></div> odd_dialog = myOddDialog(self)<br></div> response = odd_dialog.exec_()<br></div> except:<br></div> response = failure_value<br><br></div>But this is very peculiar. Anything that the dialog could figure out during __init__(), the parent code could also figure out before it creates the dialog or shows the dialog. So I would just test for the bad condition in the main code and only display the dialog (call its .exec_() method) when the condition was good.<br><br></div>Also be aware of the nice "canned" dialogs available as static methods of QMessageBox, such as question(), warning() and so on. Read the doc for QMessageBox, it can save you a lot of effort.<br><br></div></div>