[PyQt] Signal causes seg fault

Cody Scott cody at perspexis.com
Thu Jan 12 17:43:40 GMT 2017


I'm getting a seg fault when a child class calls a method of a parent class
which emits a signal (also of the parent class).

If you run this example file and click the button it will cause a segfault.
If nothing is bound to "customType.count" then it will not segfault.

The gist and the attached file are the same.

https://gist.github.com/Siecje/4a99c2c76f65f39a57c168da10407e7f#file-signalemit-py-L19
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170112/dd5fcd5e/attachment.html>
-------------- next part --------------
import sys

from PyQt5 import QtCore, QtQml
from PyQt5.QtWidgets import QApplication


class BaseOutput(QtCore.QObject):
    countChanged = QtCore.pyqtSignal()

    def __init__(self, parent = None):
        super().__init__(parent)

    @QtCore.pyqtProperty(int, notify = countChanged)
    def count(self):
        return 1
    
    @QtCore.pyqtSlot()
    def setCount(self):
        self.countChanged.emit() # Seg fault after this line

class CustomType(BaseOutput):
    def __init__(self, parent = None):
        super().__init__(parent)


QML = b"""
import QtQuick 2.7
import QtQuick.Controls 1.4

import CustomType 1.0

ApplicationWindow {
    visible: true
    width: 800
    height: 600

    CustomType {
      id: customType
    }

    Column {
      Text { text: customType.count }
      Button {
        text: "Change count"
        onClicked: {
          customType.setCount()
        }
      }
    }
}

"""

app = QApplication(sys.argv)
QtQml.qmlRegisterType(CustomType, 'CustomType', 1, 0, 'CustomType')
engine = QtQml.QQmlApplicationEngine()
engine.loadData(QML)

app.exec_()


More information about the PyQt mailing list