PySide:将 QItemSelectionModel 与 QListView 一起使用时的 Segfault(?)

2023-02-20Python开发问题
1

本文介绍了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(?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

在xarray中按单个维度的多个坐标分组
groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)...
2024-08-22 Python开发问题
15

Pandas中的GROUP BY AND SUM不丢失列
Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)...
2024-08-22 Python开发问题
17

GROUP BY+新列+基于条件的前一行抓取值
Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)...
2024-08-22 Python开发问题
18

PANDA中的Groupby算法和插值算法
Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)...
2024-08-22 Python开发问题
11

PANAS-基于列对行进行分组,并将NaN替换为非空值
Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)...
2024-08-22 Python开发问题
10

按10分钟间隔对 pandas 数据帧进行分组
Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)...
2024-08-22 Python开发问题
11