连接信号和插槽时出现分段故障

时间:2015-03-18 13:18:20

标签: qt segmentation-fault pyside

我已将代码简化为以下几行:

#-*- coding:utf8 -*-

from PySide.QtCore import *
from PySide.QtGui import *
import sys

app = QApplication(sys.argv)

table = QTreeView()
table.setModel( QStandardItemModel() )

@Slot(QItemSelection, QItemSelection)
def someSlot(selected, deselected):
    print "Slot Triggered"
    # do something ...

table.selectionModel().selectionChanged.connect(someSlot) # <-- error caused by this line !

当我尝试将Slot连接到selectionChanged Signal时,我收到了分段错误错误:

Segmentation fault (core dumped)

我的代码出了什么问题?

1 个答案:

答案 0 :(得分:1)

在应用运行时保持selectionModel引用:

#table.selectionModel().selectionChanged.connect(someSlot)
selectionModel = table.selectionModel()
selectionModel.selectionChanged.connect(someSlot)