Unsolved QList of C++ custom objects to QML
-
Hello,
Here is my need. I am reading an XML file in the C++ side of my application, and create some C++ objects of mine. After the reading, I send a signal to the QML to tell my GUI it has some QML components to dynamically instanciates.
I want those components to be initialized with the properties of the C++ objects I have created during the reading of the XML file.
So the idea here is to send a list of C++ objects to the QML, and parse that list inside the QML to create components.
I had a look at the QVariant class, but don't really know how to use it.
For example, I currently have aQList<MyObjects*>
that I want to expose to the QML via a Q_INVOKABLE method.
How do I do that? Does aQList<QVariant*>
will be enought?Regards,
-
@bguivarch said in QList of C++ custom objects to QML:
How do I do that? Does a QList<QVariant*> will be enought?
Yes. But use
QList<QVariant>
instead. When you registered the list contents (in the variant) to the meta type system (Q_DECLARE_METATYPE
) you can access it's QObject properties from QML. -
Hello,
Thanks for your answer.
To access the properties of the objects in the list, do I have to convert these properties to
Q_PROPERTY
or is that unnecessary? With my understanding of QML, I would say that I have to.Regards
-
@bguivarch said in QList of C++ custom objects to QML:
With my understanding of QML, I would say that I have to.
exactly, since QML uses the meta type system.
-
Hello,
Ok thanks for this additional explanation.
I'll give it a try and let you know if I face some difficulties.Regards