PySide6 ListProperty causes segfault?
-
I cannot get the PySide6 'ListProperty' to work correctly. I get segfaults on Ubuntu and on MacOS I get a hung Python process with no QT window displayed. I cannot test on Win10 because I cannot get PySide6 to install correctly.
This is a stripped-down example that
- Has a 'ListPropertyObj' that holds the ListProperty.
- This is just supposed to be a simple 'list of wrapped strings'.
- Has a simple string wrapper called 'ListPropertyElement' so I have a QObject to give to the ListProperty type
- Simple ListView trying to use this ListProperty as a model.
import sys from pathlib import Path from typing import List from PySide6.QtCore import QObject, Slot, Property, Signal from PySide6.QtGui import QGuiApplication from PySide6.QtQml import QQmlApplicationEngine, QmlElement, ListProperty from PySide6.QtQuickControls2 import QQuickStyle QML_IMPORT_NAME = "io.qt.textproperties" QML_IMPORT_MAJOR_VERSION = 1 @QmlElement class ListPropertyElement(QObject): _value: str def __init__(self, parent=None): super().__init__(parent) self._value = "N/A" def getValue(self): return self._value def setValue(self, value:str): self._value = value value = Property(str, fget=getValue, fset=setValue) @QmlElement class ListPropertyObj(QObject): _items: List[ListPropertyElement] def __init__(self, parent=None): super().__init__(parent) self._items = [] def appendItem(self, item:ListPropertyElement): self._items.append(item) def countItems(self): return len(self._items) def itemAt(self, index:int): return self._items[index] items = ListProperty(ListPropertyElement, count=countItems, at=itemAt, append=appendItem) if __name__ == '__main__': app = QGuiApplication(sys.argv) QQuickStyle.setStyle("Material") engine = QQmlApplicationEngine() qml_file = Path(__file__).parent / 'main.qml' engine.load(qml_file) if not engine.rootObjects(): sys.exit(-1) sys.exit(app.exec())main.qml
import QtQuick 2.0 import QtQuick.Controls 2.1 import QtQuick.Window 2.1 import QtQuick.Controls.Material 2.1 import io.qt.textproperties 1.0 ApplicationWindow { id: page width: 800 height: 400 visible: true Material.theme: Material.Dark Material.accent: Material.Red ListPropertyObj { id: listPropertyObj items: [ ListPropertyElement { value: "one" }, ListPropertyElement { value: "two" } ] } ListView { model: listPropertyObj.items anchors.fill: parent delegate: Text { text: index color: "white" } } }You will note that I'm not even really accessing the list in this example. The ListView delegate is only accessing the 'index'. Perhaps I'm missing something but Google doesn't turn up much about ListProperty. Am I supposed to be using something else? If I don't try to access the ListProperty then I don't get the segfault.
- Has a 'ListPropertyObj' that holds the ListProperty.