View Full Version : Help with QML, JavaScript and C++

7th February 2011, 21:52
Can a C++ file and Qml File Share the same javascript file , if it is possible how Can we do that.


9th February 2011, 23:08
Would you care to elaborate? What do you mean "share a javascript file"? How does C++ use javascript files?

11th February 2011, 20:23
Thanks "Master of Zen" At last someone wanted to answer my question
I will elaborated as much as i can,

I am Learning Qt and QML using the Declarative example and out of that i used the Calculator example where the Qml file makes use of Java script File for calculating the values, so in the process of learning i am trying to get the same calculated value form the Java script file to on of the Forms i have in the QT application, so what i tried to do is opening the Qml calculator file on button click on the Qt form and trying to get the calculated value back on to a text box in the Qt form but not on to the display on to the calculator.qml . what i thought is if there is a way that i can make use of same java script file for getting the value to the text box in Qt form. presently i am studying through the documents for integrating Qml and C++. i am still not able to figure out what to do .so if anyone could guide me in the right direction, it would be a great help.

11th February 2011, 23:23
If you design your (javascript) code right, you can use QScriptEngine to run a javascript function. This is more or less what QML does behind the scenes anyway.

14th February 2011, 19:46
Okay, Can you please give me an example of right design.... or what it can possible look like.... just the algorithmic part....

14th February 2011, 22:42
Just expose the javascript function so that the engine can use it.