如果我有 C++ 中的内容列表,如何将其公开给 QML(在 Qt5 / QtQuick 2 中)?似乎 QML 只能理解QObject
- 派生类,这是一个问题,因为QObject
s 不能放入 aQList
或复制。我该怎么做呢:
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;
// ...
};
这样我就可以在 QML 中做这样的事情:?
var a = thingManager.things[0].name;