What is the simplest way of exposing a vector of custom c++ objects with Q_Properties to qml?
-
Hi,
I have a class like this
class MyClass{ Q_GADGET Q_PROPERTY(QString programName READ programName) Q_PROPERTY(QDateTime timeStamp MEMBER _timestamp) Q_PROPERTY(QUrl iconFile MEMBER _icon)
I did notmake it a
QObject
, as otherwise I get errors regardingcall to implicitly-deleted copy constructor
, as I use the implicit copy constructor of my object at other places.Then I have a std::vector<MyClass> of these objects. What is the simplest way of exposing my vector to QML so I can use it as a model with my properties as roles?
-
Hi,
What about Extending QML - Object and List Property Types Example chapter of Qt's documentation ?
-
Yes this works. I just thought if there might not be an easier way. One of the things I don't like is that I need to derive from QObject (does not work with copy constructors).
have you tried to store your Class objects in a QList<myClass> *myList?
And than access it from qml via
QVariant getClassList(){QVariant::fromValue(myList)}
works fine with QObjects, should work with QGadget, but, I'm not 100% sure.