[PyKDE] Signal destroyed() not emitted for QWidget
Giovanni Bajo
rasky at develer.com
Tue Feb 14 14:45:58 GMT 2006
Phil,
Using PyQt snapshot-20051212 and SIP snapshot-20051212, I found this bug:
----------------------------------------------------
from qt import *
app = QApplication([])
def testDestruction(cls):
def foo(o):
print "destroyed:", o
destroyed.append(o)
destroyed = []
o = cls(None)
QObject.connect(o, SIGNAL("destroyed(QObject*)"), foo)
o.deleteLater()
qApp.sendPostedEvents(o, QEvent.DeferredDelete)
assert destroyed
testDestruction(QObject)
testDestruction(QWidget)
----------------------------------------------------
destroyed: <qt.QObject object at 0x089964F8>
Traceback (most recent call last):
File "D:\Work\caligola3d\src\pyqtbug8.py", line 19, in ?
testDestruction(QWidget)
File "D:\Work\caligola3d\src\pyqtbug8.py", line 16, in testDestruction
assert destroyed
AssertionError
To me, it looks like the signal "destroyed" is emitted for QObjects but not
for QWidgets. Any idea why?
Some contest: I'm trying to construct a smarter weakref which works for
QObject the way it should work: it becomes invalid when the QObject dies
(and not only if the QObject's Python wrapper dies). If anybody has
suggestions to achieve this, that'd be pretty. My idea was to use the
destroyed() signal to find out when the QObject was destroyed and invalidate
the reference.
--
Giovanni Bajo
More information about the PyQt
mailing list