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

Posted by Rini on Stack Overflow See other posts from Stack Overflow or by Rini
Published on 2010-05-10T15:03:18Z Indexed on 2010/05/17 0:50 UTC
Read the original article Hit count: 316

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about python

Related posts about pyqt4