August 3, 2010

rikardo rikardo
Ant Farmer
10 posts

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?

2 replies

August 3, 2010

Deleted Member # 4a2 Deleted Member # 4a2
Ant Farmer
1481 posts

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

August 4, 2010

mbrasser mbrasser
Ant Farmer
452 posts

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 [doc.qt.nokia.com] functionality provided by QML.

 
  ‹‹ Alternating background color for ListViews      The Ultimate DevDays QtQuick Guide ››

You must log in to post a reply. Not a member yet? Register here!