Answer the question
In order to leave comments, you need to log in
How to pass QHash to qml?
Greetings!
I tried to do as they write in mana:
typedef QHash<int, QObject*> TControllers;
Q_DECLARE_METATYPE(TControllers)
TControllers controllers;
controllers.insert(0, myObject);
QObject * r = engine.rootObjects().at(0);
r->setProperty("controls", QVariant::fromValue(controllers));
id: main
property var controls;
MouseArea {
anchors.fill: parent
onClicked: {
console.log(main.controls);
for (var p in main.controls) {
console.log("control", p, main.controls[p]);
}
}
}
qml: QVariant(TControllers)
Answer the question
In order to leave comments, you need to log in
QHash is not inherited from QObject, so just using it in QML will not work, because C++/QML integration works through Qt's meta-object system.
It is possible to write a hash wrapper class inherited from QObject that implements its properties and methods via Q_PROPERTY, Q_INVOKABLE, and public slots.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question