python – 是否可以查询PyQt4 QObject以确定底层C实例是否已被销毁?

destroyed()信号可以被捕获用于QObject,但我想简单地测试Python对象是否仍然引用有效的C Qt对象.有没有直接这样做的方法?
如果导入sip模块,则可以调用其.isdeleted函数.

import sip
from PyQt4.QtCore import QObject

q = QObject()
sip.isdeleted(q)
False

sip.delete(q)
q
<PyQt4.QtCore.QObject object at 0x017CCA98>

q.isdeleted(q)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: underlying C/C++ object has been deleted
翻译自:https://stackoverflow.com/questions/5122451/can-a-pyqt4-qobject-be-queried-to-determine-if-the-underlying-c-instance-has-b

转载注明原文:python – 是否可以查询PyQt4 QObject以确定底层C实例是否已被销毁?