使用下面的代码,我的预览小部件的__del__
方法永远不会被调用。如果我取消注释“del window
”这一行,它就行。为什么?未使用父窗口删除QWidget
#!/usr/bin/env python
from PyQt4 import QtGui
class Preview(QtGui.QWidget):
def __init__(self, parent):
QtGui.QWidget.__init__(self, parent)
def __del__(self):
print("Deleting Preview")
class PreviewWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.widget = Preview(self)
self.setCentralWidget(self.widget)
def __del__(self):
print("Deleting PreviewWindow")
if __name__ == "__main__":
app = QtGui.QApplication(["Dimension Preview"])
window = PreviewWindow()
window.show()
app.exec()
# del window
它为我在Fedora的Linux 14(PyQt的4.8.3,Python 2.7版) 。不过,我不得不将app.exec()更改为app.exec_()。 – xioxox
@xioxox。你确定_both_'__del__'方法被调用吗? – ekhumoro
是的 - 他们为我做的 – xioxox