[PyQt] signals to python-alive, Qt-dead objects

Phil Thompson phil at riverbankcomputing.com
Fri Apr 23 13:45:09 BST 2010

On Fri, 23 Apr 2010 10:59:02 +0200, Martin Teichmann
<martin.teichmann at mbi-berlin.de> wrote:
> Hi List,
> taking the risk of annoying people by asking again,
> (I didn't get a response last time)
> I would like to kindly ask if the following behavior is
> really intended for PyQt4:
> If a QObject is not used anymore, it gets deleted by
> Qt, and eventually garbage collected some time later.
> In the meantime, however, PyQt4 still delivers signals
> to the object, leading to a RuntimeError, since the
> C++ object is already deleted. C++ has the standard
> behaviour that upon deletion of an object, all signals
> automatically get disconnected. This is very useful,
> since I (as a programmer) don't need to care about this
> anymore.
> So, if this intended behaviour, how do I go about it?
> Sure, I could write a try:...except RuntimeError: around
> every method that I use as a slot, but that's some pain.
> If that was directly implemented in PyQt4, it would be
> much simpler: a simple if statement that checks
> if a QObject is still C++-alive before delivering signals would
> do the job. I also cannot see any drawbacks: since the
> receiving object cannot do much anymore anyway,
> given that its object has been deleted, I cannot imagine
> that anyone depends on the current behaviour.
> I re-send the code that shows the problem, I just tested
> it with PyQt 4.7.3 under Python 2.6 and Windows XP.
> Note that the garbage collection at the very end does
> make a difference, which it should never do, since
> it happens at random intervals and is thus not
> reliable (all of which is intended behaviour).

It will be fixed in tonight's SIP snapshot.


More information about the PyQt mailing list