[PyQt] Slots being called on deleted QObjects

Phil Thompson phil at riverbankcomputing.com
Sun Apr 6 17:54:32 BST 2014

On 06-04-2014 5:39 pm, Jeremy Sanders wrote:
> Phil Thompson wrote:
>> That would be an incompatible change. Any slot can be called from 
>> any
>> signal. The problem only arises if you try to do something that 
>> requires
>> the underlying C++ QObject. The comment mentions destroyed() only
>> because that was the context in which the bug was reported (and it 
>> is
>> guaranteed to happen with that particular signal) but it can apply 
>> to
>> any signal.
> Thanks Phil. These are QWidgets which I'm modifying when my program 
> emits a
> documentChanged() signal. There are race conditions where 
> documentChanged()
> is emitted after the Qt object has been deleted. This seems quite 
> nasty as
> you get random crashes which are hard to test for.
> Is using @pyqtSlot the only workaround? Should I be using this for 
> every
> slot which does something to the QObject if the signal is emitted 
> from
> Python?

Not as a general rule - only to avoid fixing your race condition 
properly :)

> I assume the @pyqtSlot works because the signal is delivered via Qt 
> and
> therefore never makes it because there is no Qt object.



More information about the PyQt mailing list