You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Monday, March 19th 2012, 1:05pm

2 qml call 1 function in javascript

Hi,

I create 2 files qml: a.qml, b.qml and 1 file javascript: c.js.
In c.js, i create variable d: var d
I import c.js into a.qml and b.qml
Then in a.qml, i set d = 9
Then when i call d in b.qml ==> undefined.
I don't understand why 2 variables d are differents.
Please help me!

Thanks!

2

Monday, March 19th 2012, 2:01pm

because they are in different scopes.

http://qt-project.org/doc/qt-4.8/qdeclarativescope.html
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

3

Monday, March 19th 2012, 6:31pm

Thanks, but i can't do it. When i call d in b.qml, i want to show 9.
What must i do?
Please!

4

Monday, March 19th 2012, 8:04pm

dont know how you pass 'variables' around in jscript or qml, sorry.

Maybe this helps:
http://www.developer.nokia.com/Community…QML-pages-files
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

5

Tuesday, March 20th 2012, 3:42am

My code looks like:

Source code

1
2
3
a.qml{import "c.js" as c...c.d = 9...}
b.qml{import "c.js" as c1...console.log(c1.d)   ==> undefined...}
c.js{var d}


I tried but i can't show d = 9 when i call console.log(c1.d) in b.qml?Please help me!Thanks!