Quantcast
Channel: Active questions tagged qtquick2 - Stack Overflow
Viewing all articles
Browse latest Browse all 137

Accessing C++ QLists from QML

$
0
0

If I've got a list of things in C++, how do I expose that to QML (in Qt5 / QtQuick 2)? It seems like QML can only understand QObject-derived classes, which is an issue because QObjects can't be put in a QList or copied. How do I do this:

struct Thing{    int size;    QString name;};class ThingManager : public QObject{    Q_OBJECT    // These macros support QtQuick, in case we one day want to use it to make a slick    // interface (when QML desktop components are released).    Q_PROPERTY(QList<Thing> things READ things NOTIFY thingssChanged)public:    // ...    QList<Thing> things() const;    // ...};

So that I can do something like this in QML:?

var a = thingManager.things[0].name;

Viewing all articles
Browse latest Browse all 137

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>