[SOLVED] QQmlListProperty: QObject subclass usage
-
I have a QObject subclass like in "this":http://qt-project.org/doc/qt-5.0/qtquick/qml-referenceexamples-properties.html example, and I have a list property in it:
@class Subclass: public QObject
{
Q_OBJECT
Q_PROPERTY(QQmlListProperty<Subclass> content READ content)
QList<Subclass*> mContent;
public:
QQmlListProperty<Subclass> content() {return QQmlListProperty<Subclass>(this, mContent);}
}@I don't see any difference, however if I try to set it from QML, I get "Cannot assign multiple values to a singular property". BUT! With the following code everything works:
@class Subclass: public QObject
{
Q_OBJECT
Q_PROPERTY(QQmlListProperty<QObject> content READ content)
QList<QObject*> mContent;
public:
QQmlListProperty<QObject> content() {return QQmlListProperty<QObject>(this, mContent);}
}@Can you tell me what is wrong? I do want QQmlListProperty<Subclass> to have an automatic typecheck, because I need that only Subclass and it's children to be set as "content".
-
Hi,
Do you register "Subclass" with the QML type system via qmlRegisterType()?
Cheers,
Chris. -
OMG!
Well, that solved the whole thing :) I were using Sub-Subclasses from QML and those were registered, while Subclass itself wasn't.
Thank you very much! -
damm, had the same problem.
for the record, the error message was
Invalid property assignment: "roles" is a read-only property
where
Q_PROPERTY(QQmlListProperty<ModelRole> roles READ roleObjects)