QML Javascript help
-
I am trying to integrate QML and Javscript following this link
"Click Here":http://doc.qt.nokia.com/4.7-snapshot/qdeclarativejavascript.html
So when i import js file and then when i run it it displays this error
@
TypeError: Result of Expression 'Math.factorial' [undefined] is not a function.
@here is the code
QML
@
import Qt 4.7
import "factorial.js" as MathItem {
width: 200; height: 200
MouseArea {
anchors.fill: parent
onClicked: console.log(Math.factorial(10))
}
}
@here is factorial.js
@
function factorial(a) {
a = parseInt(a);
if (a <= 0)
return 1;
else
return a * factorial(a - 1);
}
@what is the wrong here?
-
Change Math to MyMath. The "as" name must be unique, but Math is a pre-existing name.
-
@import Qt 4.7
import "factorial.js" as Math1Item {
width: 200; height: 200
MouseArea {
anchors.fill: parent
onClicked: console.log(Math1.factorial(10))}
}
@