QtRO, How to make repc (.rep) customtype accessible in qml?
-
In my replica file (.rep) i want to use a customtype, which is defined outside of this replica,
as a property of the interface and access its members and methods via qml.Current rep file looks like this:
#include <CustomClass> class CustomInterface { PROP(QList<mynamespace::CustomClass> list SOURCEONLYSETTER) }
Simulation works but, i cannot access "list" in qml. Calls on members or functions gives me always "undefined".
(like: CustomInterfaceReplica.list.member or CustomInterfaceReplica.list.method)Unfortunately the official doc does not give a lot of information
about how to use custom classes correctly with rep files.
https://doc.qt.io/qt-6/qtremoteobjects-repc.htmlMy current solution is to write all members of CustomClass to a qvariantmap and expose it to qml with QStandardItemModel.
What i found out:
- PROP(CustomClass*) does not build.
- PROP(QList<CustomClass*>) does crash in application
- PROP(QList<CustomClass>) cannot be accessed in qml
- POD CustomType(QString name, CustomClass value) does not build.
- CLASS(CustomClass) works, if CustomClass is also declared in the rep file.
- CLASS(CustomClass) does not build, if CustomClass is not declared in a rep file.
-
Custom types work. Needs #include for the appropriate header for your type, make sure your type is known to the metabject system, and make sure it supports Queued Connections (see Q_DECLARE_METATYPE and qRegisterMetaType
Did you register your custom type with the metaobject system?
-
@Redman said in QtRO, How to make repc (.rep) customtype accessible in qml?:
Q_DECLARE_METATYPE
I tried Q_DECLARE_METATYPE, qRegisterMetaType and qmlRegisterType with CustomType and QList<CustomType>. Does not help.
When i do this in qml:
Connections { target: CustomInterfaceReplica function onListChanged(list) { tabButtonSplit.text = list[0].myProperty } }
text shows "undefined".
when i call list[0].toString()
it shows "QVariant(QList<mynamespace::CustomClass, )"