[PyQt] Slots being called on deleted QObjects

Phil Thompson phil at riverbankcomputing.com
Mon Apr 7 10:05:22 BST 2014

On 06-04-2014 7:44 pm, Jeremy Sanders wrote:
> Phil Thompson wrote:
>> Not as a general rule - only to avoid fixing your race condition
>> properly :)
> Isn't it a race condition inside PyQt? If I have lots of QWidgets 
> listening
> for a signal, surely it's not my code's fault if they still receive 
> signals
> after they've been deleted? Ideally, the Python code shouldn't have 
> to worry
> about the lifetime of the C++ object.
> The document doesn't know anything about the widgets which are 
> displaying
> it, so it can't disconnect them. Is there a reliable way to get the 
> QWidgets
> to disconnect from the signal before deletion?

Hmm - I'm struggling to disagree with you. The original change was 
clearly an incompatible (and undocumented) change.

An option would be to add a 'check_receiver' flag to the connect() 
method of a bound signal that caused the original check for a deleted 
C++ receiver to be reinstated.

What would the default be? Reinstating the check by default would be 
another incompatible change (though documented this time) but would be 
fixing a 2 year old regression, and would be the "right thing" for the 
vast majority of cases.


More information about the PyQt mailing list