[PyQt] Signals and "RuntimeError: wrapped C/C++ object of type XXX has been deleted"

Jeremy Sanders jeremy at jeremysanders.net
Wed Nov 20 18:57:07 GMT 2013


I'm getting problems in my app where a Python QWidget object receives 
signals after the C/C++ widget has been deleted. This gives the usual 
frustrating error "RuntimeError: wrapped C/C++ object of type XXX has 
been deleted".

I'm emitting old-style Python signals which look like this
         self.emit( qt4.SIGNAL("sigModified"), ismodified )
...
         self.connect(self.document, qt4.SIGNAL("sigModified"),
                      self.slotDocModified)

What I'm doing is listening for changes in a document in a widget class, 
which shows a document status.

I would have thought that when a C++ object (the widget) is deleted, the 
signal should become disconnected. This doesn't seem to be happening - 
the connection remains after the C++ object has gone.

This is with
Python version: 2.7.1/2.7.4 (seen on Linux and Windows)
Qt version: 4.8.5
PyQt version: 4.10.3 / 4.10
SIP version: 4.15.3 / 4.14.5

Is this a bug? I've managed to fix a couple of these where it's obvious 
where the widget is deleted, so I disconnect the signal first. In other 
places I can't see an obvious way to do this - where can I clear up 
signals of random widgets? This seems like a hack and I would have 
thought that signals should be deleted before the C++ object is deleted.

Thanks

Jeremy


More information about the PyQt mailing list