PDA

View Full Version : QML Global Object



coderbob
26th October 2010, 09:07
main.qml


import Qt 4.7

import "myscript.js" as MyScript

Rectangle {
id:main

MyScript.myFuction(); // This will execute fine, scope is fine
SecondQML {
}

}



myscript.js


function myFuction() {
print('inside my function');
}



SecondQML.qml



Rectangle {

MouseArea {
id: mouseArea
anchors.fill: parent
onClicked: {
MyScript.myFunction(); // Will not execute
}
}
}


I also tried main.MyScript.myFunction() it is out of scope. I need to be able to reference the same script instance from main.qml and not a newly initiated script from inside secondQML.qml

I can access main from here because of hierarchy but I am not sure why I cannot get to the MyScript property.

coderbob
3rd November 2010, 14:18
This has been answered here: http://developer.qt.nokia.com/forums/viewthread/1540/

Short Answer: "Imports are document specific (we should try to make this clearer in the docs!), which is why the above is not working. " - mbrasser