QObject
的类,这是个问题,因为QObject
不能放入QList
或者复制。我应该怎么做?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;
Q_DECLARE_METATYPE()
和/或qRegisterMetaType()
可以帮助解决问题? - Bret Kuhns