Important: Please read the Qt Code of Conduct -

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);
    QObject *viewobject = view.rootObject();
    return app.exec();

    in qml

    @Scxml {
    id: mainController
    source: "Statechart/mainSCXML.scxml"
    Component.onCompleted: registerObject(viewobject, "viewobject", true)


    Thanks for your support!

  • Moderators

    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...":
    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()

Log in to reply