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


- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01