How to use QList<CustomClass> in python with Shiboken
-
Hello,
I have a Qt/C++ project that exposes a QList of Requirement to python (with Shiboken6).This is the requirement class
namespace requirement{ class Requirement { public: ... bunch of attributes ... }; }This is another class witha slot using QList<Requirement>
namespace requirement{ class RequirementsModelBase{ public Q_SLOTS: ... virtual void addRequirements( QList<Requirement> requirements); ... }; }And Another class with a signal that I want to connect in python to the addRequirements slot
namespace requirement{ class RequirementsManager { Q_OBJECT ... Q_SIGNALS: void listOfRequirements(QList<requirement::Requirement>); ... }; }this is the python script
import sys from PySide6.QtWidgets import QApplication from PySide6.QtCore import SIGNAL, SLOT, QObject from PyTasteQtWidgets import TasteQtWidgets as QtTaste # after PySide! def random_slot(value): print(dir(value)) if __name__ == "__main__": app = QApplication(sys.argv) manager = QtTaste.RequirementsManager() model = QtTaste.RequirementsModelBase() manager.listOfRequirements.connect(random_slot) widget = QtTaste.RequirementsWidget("", manager, model) widget.show() sys.exit(app.exec())When the signal is emitted I get this error:
TypeError: Can't call meta function because I have no idea how to handle QList<requirement::Requirement>for the sake of completeness, this is the typesystem xml file used with shiboken:
<?xml version="1.0"?> <typesystem package="TasteQtWidgets"> <load-typesystem name="typesystem_widgets.xml" generate="no"/> <load-typesystem name="typesystem_core.xml" generate="no"/> <load-typesystem name="typesystem_gui.xml" generate="no"/> <namespace-type name="requirement" visible="no"> <object-type name="RequirementsWidget"> </object-type> <object-type name="RequirementsManager"> </object-type> <value-type name="Requirement"> </value-type> <object-type name="RequirementsModelBase"> <enum-type name="RoleNames"/> <enum-type name="HEADER_SECTIONS"/> </object-type> </namespace-type> </typesystem>I didn't find any documentation to use QList with any custom types so maybe someone could give me some hints on how to proceed with this.
Thank you
-
Hi and welcome to devnet,
I haven't used shiboken yet but I am wondering whether the chapter on containers might be what you are looking for.
Hope it helps
-
I think the problem is the invisible namespace. You then get a mismatch between the type names in the Qt meta type system and the ones in Python and so, the QVariant conversion fails.
-
H HugoVS has marked this topic as solved on