Unable to assign QList<MOCourse*> to QDeclarativeListModel*
-
Hey Guys -
While running my program, I get the following error after I pass a QList<MOCourse*> to be the model of a GridView element. @CourseNode.qml:273: Unable to assign QList<MOCourse*> to QDeclarativeListModel*@
I'm not sure what code is relevant to this, because all I am doing is using the variable name I assign successfully from C++ in the QML to set a model, but here are some potentially relevant lines.
In the controller class for the QML document.
@QDeclarativeView *view = w->getDeclarativeView();
QDeclarativeContext *ctxt = view->rootContext();
ctxt->setContextProperty("course100Model", QVariant::fromValue(courseList));@In the QML document itself (Note that Blade is a custom object).
@Blade {
id: blade1targetModel: course100Model@
From the Blade.qml file.
@GridView {
id: gridView1
model: targetModel@Any ideas would be greatly appreciated.
-
How did you define the <code>targetModel</code> property?
-
@property ListModel targetModel: undefined@
-
I've narrowed it down to a problem with the type of the targetModel property. I've changed my setup to use a QAbstractItemModel instead of a QList, but I get exactly the same error. What type should I use for the property? Or is there no type usable and I have to pass it some other argument to get the model?
-
Well, your context property is a QObjectList, not a ListModel. I think the easiest way to go in your case is a property alias.
@
property alias targetModel: gridView1.model
@