문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top