本文介绍了PySide:当使用QItemSelectionModel与QListView时Segfault(?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与此相同的问题:

我有一个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的appname已停止工作。我确定这是一个segfault。

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。

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?

推荐答案

尝试在选择模型的生命周期中保留对选择模型的引用。这对我有一个类似的问题(seg fault当连接到tableview选择模型的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(?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 19:44
查看更多