开发者

PyQt4: Why does Python crash on close when using QTreeWidgetItem?

开发者 https://www.devze.com 2022-12-29 23:56 出处:网络
I\'m using Python 3.1.1 and PyQt4 (not sure how to get that version number?). Python is crashing whenever I exit my application. I\'ve seen this before as a garbage collection issue, but this time I\'

I'm using Python 3.1.1 and PyQt4 (not sure how to get that version number?). Python is crashing whenever I exit my application. I've seen this before as a garbage collection issue, but this time I'm not sure how to correct the problem.

This code crashes:

import sys
from PyQt4 import QtGui

class MyWindow(QtGui.QMainWindow):

    def __init__(self, parent=None):
        QtGui.QMainWindow.__init__(self, parent)
        self.tree = QtGui.QTreeWidget(self)
        self.setCentralWidget(self.tree)
        QtGui.QTreeWidgetItem(self.tree)  # This line is the problem
        self.show()


app = QtGui.QApplication(sys.argv)
mw = MyWindow()
sys.exit(app.exec_())

If I remove the commented line, the code exits without a problem. If I remove the 'self.tree' parent from the initialization, the code exits without a problem. If I try to use self.tree.addTopLevelItem,开发者_运维问答 the code crashes again.

What could be the problem?


It does not crash with a recent SIP/PyQt version.

0

精彩评论

暂无评论...
验证码 换一张
取 消