[PyQt] SIGABRT when setting QQmlListProperty

Cody Scott cody at perspexis.com
Thu Jan 12 21:05:16 GMT 2017


I'm using PyQt5==5.7.1.

I'm trying to set a list property from QML. I'm using @pyqtProperty
(QQmlListProperty)
I'm getting an error that TypeError: list element must be of type 'str',
not 'NoneType' but they are strings in QML.

After that I get a SIGABRT.

Code and output here.
https://gist.github.com/Siecje/0a6cb1b49358f9373496bd8952bfd1fd

The gist and the attached file are the same.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170112/7672f499/attachment-0001.html>
-------------- next part --------------
import sys

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


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

        self._names = []

    @QtCore.pyqtProperty(QtQml.QQmlListProperty)
    def names(self):
        return QtQml.QQmlListProperty(str, self, self._names)
    @names.setter
    def names(self, names):
        print('Never see this')
        self._names = names

QML = b"""
import QtQuick.Controls 1.4

import CustomType 1.0

ApplicationWindow {
    visible: true
    width: 800
    height: 600

    CustomType {
      id: customType
      names: ["one", "two"]
      //names: [] // doesn't crash
    }
}
"""

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