QObject实例化中的PySide分段错误

Dje*_*ent 13 python segmentation-fault pyside python-3.x

我有一个类是我的其他非qt类的基础.该类使用Signal实例实例化QObject类.不幸的是,有时它会引发Segmentation Fault错误.这是我的代码:

class PublisherSignal(QObject):
    notify = Signal(list)


class PublisherBase:
    def __init__(self, *args, **kwargs):
        super(PublisherBase, self).__init__(*args, **kwargs)
        self._signal = PublisherSignal()
Run Code Online (Sandbox Code Playgroud)

错误处理程序显示,分类错误发生在PublisherSignal()类实例化上.并非总是如此.在大多数情况下,它工作正常.没有线程涉及.子类PublisherBase不是子类QObject.
段错误的原因是什么?

mck*_*rly 4

第一:Segmentation fault对于开发人员来说是一个复杂的问题。要有效地处理它,请使用错误处理程序。它是 Python v.3.x 的一部分,但您可以使用pip将其安装在 Python v.2.x 中。但有时你最好使用事件过滤器注册\xe2\x80\x93\xc2\xa0小部件来跟踪信号事件。这是鼠标的示例(只是为了看看它是什么样子):

\n\n
# IT IS JUST AN EXAMPLE (NOT A SOLUTION)\n\ndef eventFilter(self, source, event):\n    if event.type() == QEvent.MouseButtonPress:\n        if source == self.txtEditor :\n            pos=event.pos()\n            cursor=self.txtEditor.cursorForPosition(pos)\n            cursor.select(QTextCursor.WordUnderCursor)\n            txtClicked=cursor.selectedText()\n            self.testCommand(str(txtClicked))\n    return QMainWindow.eventFilter(self, source, event)\n
Run Code Online (Sandbox Code Playgroud)\n\n

第二:您可以使用Python 调试器模块:

\n\n
python -m pdb yourScript.py\n
Run Code Online (Sandbox Code Playgroud)\n\n

第三:对于涉及线程(但你说不涉及线程)。

\n\n
shutdown (exit) can hang or segfault with daemon threads running\n
Run Code Online (Sandbox Code Playgroud)\n