python - PyQt4:为什么使用 QTreeWidgetItem 时 Python 会在关闭时崩溃?

标签 python pyqt4 python-sip

我正在使用 Python 3.1.1 和 PyQt4(不知道如何获取该版本号?)。每当我退出应用程序时,Python 就会崩溃。我以前曾将此视为垃圾收集问题,但这次我不确定如何纠正该问题。

此代码崩溃:

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_())

如果我删除注释行,代码将毫无问题地退出。如果我从初始化中删除“self.tree”父级,代码将毫无问题地退出。如果我尝试使用 self.tree.addTopLevelItem,代码会再次崩溃。

可能是什么问题?

最佳答案

最新的 SIP/PyQt 版本不会崩溃。

关于python - PyQt4:为什么使用 QTreeWidgetItem 时 Python 会在关闭时崩溃?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2803704/

相关文章:

c++ - Python SIP 暴露函数

python - 以下 Python 脚本中的缩进错误

python - 如何告诉 Django ORM 反转查询结果的顺序?

python - 使用集成的小部件。 PyQT 与 Tkinter

python - pyinstaller错误: OSError: Python library not found: libpython3. 4mu.so.1.0, libpython3.4m.so.1.0, libpython3.4.so.1.0

python - 是否可以让 QWebKit 显示 pdf 文件?

python - 如何根据数据框列值将目录中的图像组织成类?

python - 如何使用 python win32com.client 在 Excel 中添加折线?

python - PyQt5安装错误(QtCore模块错误: Unable to create the C++ code)

macos - PyQt 安装期间 SIP 版本检查不正确