I want to access QML from QML. Here is a sample code
class A; Class B: Public QObject {... Q_INVOKABLE QQmlListProperty & lt; A & gt; Read (); ... Private: QList & lt; A * & gt; Lst; } I am using reference property to access the object of qml in class B. Any sample code I can access in qml will be useful
You will see the Q_DECLARE_METATYPE (A *) will need to be able to wrap it in a QVariant for use in QML
but to just reference it and pass it to QML is.
If you have to code as a CML, it must inherit QObject and execute properties, slots and such.
How can you implement QQmlListProperty here:
In addition to this, if QObject is too heavy for you and in them If you have a lot, you always get a QObject non- QObject to be used as a controller, but is still registered as a MetaType type.
class A {public: int a; }; Q_DECLARE_METATYPE (A *) Class AROCO: Public QObject {Q_OBJECT Public Slot: QVariant aVar} {return aVar.value & lt; A * & gt; () - & gt; A; } Zero set A (QVariant aVar, int v) {aVar.value & lt; A * & gt; () - & gt; A = v; }}; In this way you do not have the limitations of size overhead and QObject for every object in the list, and instead using a controller to access the data Although, in your case, you can use B to act as both container and controller proxy for low performance.
No comments:
Post a Comment