javascript function in QML
Unsolved
QML and Qt Quick
-
wrote on 22 Nov 2015, 07:36 last edited by ansh
Why I'm not getting the desired result in the following code?
Item { id: root width: 200 height: 200 function foo() { var l = 2+2; } Component.onCompleted: { var str = foo.toString(); console.log(str) } }
It's giving me
function() { [code] }
rather thenfunction foo() { var l = 2+2; }
.What's the reason for such behaviour? -
wrote on 22 Nov 2015, 15:41 last edited by
Because you must use return in your function.
Of course not need to convert function to String, check blow code :)Item { id: root width: 200 height: 200 function foo() { var l = 2 + 2; return l; } Component.onCompleted: { console.log(foo()) } }
-
wrote on 22 Nov 2015, 16:23 last edited by
My desired output is
function foo() { var l = 2+2; }
.
3/3