Expose QObject to QML
-
Hi,
I try to use an old qt-lab called qmlscxml to load SCXML files to control a qml interface.
I need to expose a QObject to QML but I have the following error:
ReferenceError: Can't find variable: viewobject
I'm new with Qt but I read some doc and don't find what is wrong.
The code is below:
in ccp
@int main(int argc, char ** argv)
{
qmlRegisterType<QmlScxml>("Scxml", 1, 0, "Scxml");
QApplication app(argc, argv);
QDeclarativeView view(NULL);
view.setSource(QUrl::fromLocalFile("qml/subscreen/main.qml"));
QObject *viewobject = view.rootObject();
view.engine()->rootContext()->setContextProperty("viewobject",viewobject);
view.show();
return app.exec();
}@in qml
@Scxml {
id: mainController
source: "Statechart/mainSCXML.scxml"
Component.onCompleted: registerObject(viewobject, "viewobject", true)}@
Thanks for your support!
-
I'm confused. Why are you trying to set rootObject as context in rootContext?
-
I use the qt-scxml project "Your text to link here...":http://qt.gitorious.org/qt-labs/scxml
I need to register the rootObject to the qstatemachine. Doing that I can acces from the scxml file to function defined in qml with: viewobject.dothis() or detect signal emit from the rootObject with: viewobject.timeout()