Hi,
<p>
I've made a Python class that extends <code>QOpenGLWidget</code>, and needs to clean up some OpenGL objects when it's destroyed. The Qt documentation for this says cleanup code should be called by the destructor and when the <code>QOpenGLContext::aboutToBeDestroyed</code> signal is emitted, so I've tried calling my cleanup method from <code>__del__</code> and connecting it as a slot to the signal.
<p>
Unfortunately, the signal isn't emitted when the widget is destroyed, just when the widget has its context replaced, and <code>__del__</code> seems to be called too late as calling some of the C++ methods doesn't work (no exception is thrown, but nothing after the call is executed).
<p>
The next approach I tried was connecting the cleanup method to the widget's <code>destroyed</code> signal, which required a lambda as mentioned <a href="https://machinekoder.com/how-to-not-shoot-yourself-in-the-foot-using-python-qt/" target="_top" rel="nofollow" link="external">here</a>. This signal isn't emitted until after <code>__del__</code> has been called, and so I get exceptions due to the C++ object no longer existing.
<p>
The only approach I've had success with is getting the widget's parent and connecting to <i>its</i> <code>destroyed</code> signal, but this doesn't seem especially robust - I can imagine situations where a hypothetical widget wouldn't necessarily have a parent when it was destroyed, but may well still need to do cleanup.
<p>
Is there a nicer way of doing this, for example, a method that SIP will call as the first thing the C++ destructor does, so that nothing's been destroyed yet? If not, could something like that be added?

        
        
        
<br/><hr align="left" width="300" />
Sent from the <a href="http://python.6.x6.nabble.com/PyQt-f1792048.html">PyQt mailing list archive</a> at Nabble.com.<br/>