11-08-2012 05:32 AM
In my c++ code i have a QList<MyClass>
In QML i want to show a number of containers that contain information about the particular MyClass, like name.
The list is accessible with a getter from Class2
I use
qml->setContextProperty("class2", class2);
to publish the c++ Class2 (extends QObject) to qml.
To get the list i define a getter with Q_INVOKABLE in the class:
Q_INVOKABLE QList<MyClass> getMyClasses();
In QML i call it like this:
onCreationCompleted: showMyClasses();
function showMyClasses() {
var myClasses= class2.getMyClasses();
console.log("myClasses size: " + myClasses.size());
for (var i = 0; i < myClasses.size(); i ++) {
//do stuff
}
}
But i get:
TypeError: Result of expression 'myClasses' [undefined] is not an object.
Is this approach systematically flawed? Or do i just do something wrong?
Solved! Go to Solution.
11-08-2012 05:51 AM
Hi Simon,
I guess you need to register your MyClass to expose it to QML.
https://developer.blackberry.com/cascades/document
http://doc.qt.digia.com/qt/qtbinding.html
qmlRegisterType<ImageViewer>("MyClass", 1, 0, "MyClass");
11-08-2012 05:52 AM
11-08-2012 07:50 AM - edited 11-08-2012 11:24 AM
It seems that QList is not supported as a datatype, and i also have to register my custom class, trying to figure out how to connect the dots given by http://doc.qt.digia.com/qt/qtbinding.html#supporte
edit:
resolved the QObject issue.
Now i get this problem:
I use
qmlRegisterType<MyClass>("com.isec7.materials", 1, 0, "MyClass");
And in the qml
import com.isec7.materials 1.0
And get an error:
arning: bb::cascades::QmlDocument: error when loading QML from: ...
module "com.isec7.materials" is not installed
import com.isec7.materials 1.0
11-08-2012 12:38 PM
Just a few points to confirm:
11-09-2012 04:09 AM
11-09-2012 09:26 AM
You need to register the type before creating the main qml. Switch those steps around and you should be good to go.
11-09-2012 09:26 AM
11-09-2012 09:58 AM