Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top