<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<br>
<br>
<div class="moz-cite-prefix">On 2015-04-05 8:37 PM, David Cortesi
wrote:<br>
</div>
<blockquote
cite="mid:CALyzANtTcgRmUnUObBS6Ss-DQbkbnUDwLL6-xGrEDC1XLaOH-A@mail.gmail.com"
type="cite">
<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>
<br>
</blockquote>
<br>
Thank you.<br>
<br>
Your solution works for me. <br>
<br>
I agree with your statement, but i am trying to build multi dialog
application without a MDI, it just so seems fit to do computations
regarding a problem within the concerned dialog. And if no
permissible results exit just stop the dialog and return. Thinking
of other solutions like taking the initial computation outside the
dialog init i think is too much coding and tracking for errors so
just trying to keep the related bunch together.<br>
<br>
<br>
George<br>
<br>
<br /><br />
<hr style='border:none; color:#909090; background-color:#B0B0B0; height: 1px; width: 99%;' />
<table style='border-collapse:collapse;border:none;'>
<tr>
<td style='border:none;padding:0px 15px 0px 8px'>
<a href="http://www.avast.com/">
<img border=0 src="http://static.avast.com/emails/avast-mail-stamp.png" alt="Avast logo" />
</a>
</td>
<td>
<p style='color:#3d4d5a; font-family:"Calibri","Verdana","Arial","Helvetica"; font-size:12pt;'>
This email has been checked for viruses by Avast antivirus software.
<br><a href="http://www.avast.com/">www.avast.com</a>
</p>
</td>
</tr>
</table>
<br />
</body>
</html>