PySide: Segfault(?) when using QItemSelectionModel with QListView(PySide:将 QItemSelectionModel 与 QListView 一起使用时的 Segfault(?))
问题描述
与此完全相同的问题:连接 QTableView selectionChanged 信号会产生段错误PyQt
我有一个QListView,我想在选择一个项目时调用一个函数:
I have a QListView, and I want to call a function when an item is selected:
self.server_list = QtGui.QListView(self.main_widget)
self.server_list_model = QtGui.QStandardItemModel()
self.server_list.setModel(self.server_list_model)
self.server_list.selectionModel().selectionChanged.connect(self.server_changed)
但是,当它到达我正在使用选择模型的最后一行时,应用程序崩溃了.不是回溯,而是来自 Windows 的应用程序名称已停止工作".我很确定这是一个段错误.
But, when it reaches the last line, where I'm using the selection model, the app crashes. Not with a traceback, but with a "appname has stopped working" from Windows. I'm pretty sure that's a segfault.
但是,当我使用 PyQt4 时,它工作正常.我使用 PySide 因为它是 LGPL.
BUT, when I use PyQt4 it works fine. I'm using PySide because it's LGPL.
是的,我使用的是最新版本(PySide:1.2.1、Python 2.7.5、Qt 4.8.5).
Yes, I'm on the latest versions of everything (PySide: 1.2.1, Python 2.7.5, Qt 4.8.5).
谁能帮我解决这个问题?
Can anyone help me with this?
推荐答案
尝试在选择模型的生命周期内保持对选择模型的引用.这对我来说有类似的问题(连接到表视图选择模型上的 currentChanged 事件时出现段错误).
Try holding a reference to the selection model for the lifetime of the selection model. That worked for me with a similar problem (seg fault when connecting to currentChanged event on a table views selection model).
self.server_list = QtGui.QListView(self.main_widget)
self.server_list_model = QtGui.QStandardItemModel()
self.server_list.setModel(self.server_list_model)
self.server_list_selection_model = self.server_list.selectionModel() # workaround
self.server_list_selection_model.selectionChanged.connect(self.server_changed)
由于某种原因,最后两行有效,而将它们组合成一个命令会引发错误.
For some reason, the last two lines work, while combining them into one command throws an error.
这篇关于PySide:将 QItemSelectionModel 与 QListView 一起使用时的 Segfault(?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PySide:将 QItemSelectionModel 与 QListView 一起使用时的 Segfault(?)


基础教程推荐
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 筛选NumPy数组 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01