Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Expose QObject to QML

Expose QObject to QML

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 2.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gfinne
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      I'm confused. Why are you trying to set rootObject as context in rootContext?

      (Z(:^

      1 Reply Last reply
      0
      • G Offline
        G Offline
        gfinne
        wrote on last edited by
        #3

        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()

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved