<div>I truly believe you are approaching this from the wrong angle. If you need to know when your QDialog is going away, you override closeEvent and do your cleanup from there. </div><div><br></div><div>However, looking through the docs, it does not appear that destroy is actually a signal. It's called from the QWidget dtor, so it makes sense that if you call destroy(), you get the runtime error because you are deleting the C++ object before the Python object. Do not call destroy yourself - call self.close and override closeEvent. From there you can accept or reject closing the dialog, and do any cleanup prior to your dialog being destroyed.</div>
<div><br></div><div>From the Qt Docs:</div><div><br></div><div>void QWidget::destroy ( bool destroyWindow = true, bool destroySubWindows = true ) [protected]<br><br>Frees up window system resources. Destroys the widget window if destroyWindow is true.<br>
<br>destroy() calls itself recursively for all the child widgets, passing destroySubWindows for the destroyWindow parameter. To have more control over destruction of subwidgets, destroy subwidgets selectively first.<br><br>
This function is usually called from the QWidget destructor.<br></div><div><br></div><div class="gmail_quote">On Thu, Apr 7, 2011 at 3:04 AM, Rui DaCosta <span dir="ltr"><<a href="mailto:ruidc@yahoo.com">ruidc@yahoo.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div style="font-family:times new roman,new york,times,serif;font-size:12pt"><div>I know it can close it manually, the problem is that this is a simplification of a problem I had, in which we were expecting the QDialog to close as per the docs, but it did not.<br>
The *real* problem we are facing, is a bit further down the line, where we are getting the <span>"RuntimeError: underlying C/C++ object has been deleted" but we never receive a destroyed signal.<br>The only reason I need this signal or event is to do some teardown code for some callbacks to avoid getting this c++ error elsewhere.<br>
</span><div class="hm"> </div></div><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><div class="hm"><br></div><div style="font-family:times new roman, new york, times, serif;font-size:12pt">
<div class="hm"><font face="Tahoma" size="2"><hr size="1"><b><span style="font-weight:bold">From:</span></b> Demetrius Cassidy <<a href="mailto:dcassidy36@gmail.com" target="_blank">dcassidy36@gmail.com</a>><br><b><span style="font-weight:bold">To:</span></b> RuiDC <<a href="mailto:ruidc@yahoo.com" target="_blank">ruidc@yahoo.com</a>><br>
<b><span style="font-weight:bold">Sent:</span></b> Thu, 7 April, 2011 0:39:33<br><b><span style="font-weight:bold">Subject:</span></b> Re: [PyQt] why do closeEvent and destroyed slot not get called on accepting PyQt4 QDialog?<br>
</font></div><div><div class="h5"><br>If you want to close, just call self.close. It's a slot, so you can map it to any signal. Also not sure why you want to know when your widget is destroyed? Let Python take care of it, you should not need to call sip.delete yourself. closeEvent is there if you need to know _when_ your app was requested to close. If you want to allow or reject closing the app, you need to use the QEvent object which gets passed to that function. <br>

<br><div class="gmail_quote">On Wed, Apr 6, 2011 at 5:27 PM, RuiDC <span dir="ltr"><<a rel="nofollow" href="mailto:ruidc@yahoo.com" target="_blank">ruidc@yahoo.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<br>
The question & code are here:<br>
<a rel="nofollow" href="http://stackoverflow.com/questions/5570402/why-do-closeevent-and-destroyed-slot-not-get-called-on-accepting-pyqt4-qdialog" target="_blank">http://stackoverflow.com/questions/5570402/why-do-closeevent-and-destroyed-slot-not-get-called-on-accepting-pyqt4-qdialog</a><br>


<br>
but hopefully someone here can give me an answer on:<br>
1. how to get the closeEvent to fire from accepting (or do I have to do a<br>
self.close()?)<br>
2. how to get the destroyed message to print (or do I have to go through<br>
sip.delete(my_widget)?)<br>
3. why, if I comment out the del my_widget, and uncomment the<br>
my_widget.destroy() I get a:<br>
RuntimeError: underlying C/C++ object has been deleted<br>
on the destroy() without the print!  i.e. how is it that it can be destroyed<br>
but not raise the signal?<br>
<br>
Thanks in advance,<br>
R<br>
<font color="#888888">--<br>
View this message in context: <a rel="nofollow" href="http://old.nabble.com/why-do-closeEvent-and-destroyed-slot-not-get-called-on-accepting-PyQt4-QDialog--tp31336229p31336229.html" target="_blank">http://old.nabble.com/why-do-closeEvent-and-destroyed-slot-not-get-called-on-accepting-PyQt4-QDialog--tp31336229p31336229.html</a><br>


Sent from the PyQt mailing list archive at Nabble.com.<br>
<br>
_______________________________________________<br>
PyQt mailing list    <a rel="nofollow" href="mailto:PyQt@riverbankcomputing.com" target="_blank">PyQt@riverbankcomputing.com</a><br>
<a rel="nofollow" href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt" target="_blank">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><br>
</font></blockquote></div><br>
</div></div></div></div>



</div></div></blockquote></div><br>