gpt4 book ai didi

python - PySide:将 QItemSelectionModel 与 QListView 一起使用时出现段错误(?)

转载 作者:太空狗 更新时间:2023-10-29 20:42:25 25 4
gpt4 key购买 nike

与此完全相同的问题:Connecting QTableView selectionChanged signal produces segfault with PyQt

我有一个 QListView,我想在选择一个项目时调用一个函数:

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 已停止工作”。我很确定这是一个段错误。

但是,当我使用 PyQt4 时它工作正常。我正在使用 PySide,因为它是 LGPL。

是的,我使用的是最新版本(PySide:1.2.1、Python 2.7.5、Qt 4.8.5)。

谁能帮我解决这个问题?

最佳答案

尝试在选择模型的生命周期内保留对选择模型的引用。这对我有类似的问题(连接到 TableView 选择模型上的 currentChanged 事件时出现段错误)。

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)

出于某种原因,最后两行有效,而将它们组合成一个命令会引发错误。

关于python - PySide:将 QItemSelectionModel 与 QListView 一起使用时出现段错误(?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19211430/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com