Expose QJsonObject as QProperty
Unsolved
QML and Qt Quick
-
Hi everyone,
I have a class that is a QML_ELEMENT like
//file.hpp class DropBox :public QObject { Q_OBJECT Q_PROPERTY(QJsonObject amountJson READ getAmountJson NOTIFY amountJsonChanged) QML_ELEMENT QML_SINGLETON ...
When using it as singleton in QML as
//File.qml jsob:(Node_Conection.state)?DropBox.amountJson:{}
This works but if I run the qmllint it returns
Warning: /../../BoxMenu.qml:45:53: Type "QJsonObject" of property "amountJson" not found. This is likely due to a missing dependency entry or a type not being exposed declaratively. [unresolved-type] jsob:(Node_Conection.state)?DropBox.amountJson:{}
So what is the best practice to expose a QJsonObject property to QML from C++.
Another question,
If using the object not as a singleton but like
//file.hpp class DropBox :public QObject { Q_OBJECT Q_PROPERTY(QJsonObject amountJson READ getAmountJson NOTIFY amountJsonChanged) QML_ELEMENT ...
And using the class in a QAbstractListModel
like
/file.hpp class BoxModel : public QAbstractListModel { Q_OBJECT Q_PROPERTY(int count READ count NOTIFY countChanged) QML_ELEMENT ... QList<DropBox*> boxes;
In the qml delegate I normally write
//Delegate.qml Rectangle { id:root required property var amountJson;
So the delegate can get the property from the C++ model and object.
Is that the correct way to define a QJsonObject variable in qml? like using variable type 'var'?