[PyQt] Signals arriving after proxy slots deleted

Phil Thompson phil at riverbankcomputing.com
Mon Apr 16 13:00:20 BST 2012


On Mon, 16 Apr 2012 10:59:20 +0100, Andrew Suffield
<asuffield at suffields.me.uk> wrote:
> Pretty sure it's a pyqt bug, in deleteSlotProxies:
> 
>             if (QThread::currentThread() == up->thread())
>                 delete up;
>             else
>                 up->deleteLater();
> 
> http://qt-project.org/doc/qt-4.8/qobject.html#dtor.QObject
> 
> "Warning: Deleting a QObject while pending events are waiting to be
>  delivered can cause a crash. [...] Use deleteLater() instead, which
>  will cause the event loop to delete the object after all pending
>  events have been delivered to it."

But the bit you edited out said...

"You must not delete the QObject directly *if it exists in a different
thread than the one currently executing*."

...my emphasis.

> Qt makes no effort to clean out pending events when an object is
> deleted.

That's not what the documentation says...

"any pending posted events for the object are removed from the event
queue"

> deleteSlotProxies has no reason to believe that pending
> events are not waiting to be delivered - and in the case I have, there
> are pending events. It should use deleteLater unconditionally.
> 
> In fact I would suggest that it is probably always wrong for pyqt to
> delete a QObject rather than deleteLater, since it has no idea what
> the application code may have in the event queue.

Can you make the change you are suggesting and see if it makes a
difference? If it fixes the problem then it doesn't matter what the docs
say.

Phil


More information about the PyQt mailing list