【问题标题】:Segmentation fault when connecting a Signal and a Slot连接信号和插槽时出现分段错误
【发布时间】:2015-03-18 13:18:19
【问题描述】:

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

#-*- 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)

我的代码有问题吗?

【问题讨论】:

    标签: qt segmentation-fault pyside


    【解决方案1】:

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

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

    【讨论】:

    • 我使用 PySide 而不是 PyQt,当我使用 pyside 函数调整您的代码时,它总是返回一个分段错误。
    • 对不起,我的第一次 PySide 体验。解决方案是在应用运行时保留selectionModel 引用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-14
    • 1970-01-01
    相关资源
    最近更新 更多