QML objects accesible in QtScript?

  • We would like to write our application i a way that we define our UI front end with QML language (some QML components/items will be written in C++ to provide desired functionality), then we would like to access all this QML objects from javascript in QtScript.

    The goal we are trying to achieve is to develop the whole app and it's logic in javascript (QtScript). And allow developers not to bother with QML. So basically old school programming but with QML behind it to master the UI frontend.

    So as a developer I would execute the following script (example):

    var root = app.getRootQMLWidget();
    var sideBar = new QMLSideBar();
    sidebar.anchors.left = root.left;
    sidebar.anchors.top = root.top;
    sidebar.anchors.bottom = root.bottom;
    sidebar.width = 200;

    var list = new QMLMultiColumnList();
    // setting some properties on list
    list.anchors.fill = root;

    So this javascript code should dynamically build QML elements.

    Also one unrelated question, where can I find more info/docs on QSS?

  • I've been able to do lot of things with qss, just from what documentation was available in the Qt docs, http://doc.trolltech.org/4.7-snapshot/stylesheet-syntax.html

  • I don't think the model above can be done, but even it were possible it's not really a good fit for how QML was designed, and I think you'll lose a lot (if not all) of the advantages of QML in trying to develop this way (for example object.property = foo.bar in javascript performs an assignment, and doesn't establish a binding).

    That said, you should still be able to code application logic in script -- see for example the samegame or calculator demos in which all of the logic is implemented in script. The script will need to be coded in a "QML friendly" way though; for example you'll need to use the "dynamic object management":http://doc.qt.nokia.com/4.7-snapshot/qdeclarativedynamicobjects.html functionality provided by QML.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.