Results 1 to 2 of 2

Thread: QML Global Object

  1. #1
    Join Date
    Oct 2007
    Posts
    78
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QML Global Object

    main.qml
    Qt Code:
    1. import Qt 4.7
    2.  
    3. import "myscript.js" as MyScript
    4.  
    5. Rectangle {
    6. id:main
    7.  
    8. MyScript.myFuction(); // This will execute fine, scope is fine
    9. SecondQML {
    10. }
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 

    myscript.js
    Qt Code:
    1. function myFuction() {
    2. print('inside my function');
    3. }
    To copy to clipboard, switch view to plain text mode 

    SecondQML.qml
    Qt Code:
    1. Rectangle {
    2.  
    3. MouseArea {
    4. id: mouseArea
    5. anchors.fill: parent
    6. onClicked: {
    7. MyScript.myFunction(); // Will not execute
    8. }
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Oct 2007
    Posts
    78
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QML Global Object

    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

Similar Threads

  1. Replies: 4
    Last Post: 20th August 2010, 14:07
  2. Replies: 1
    Last Post: 31st July 2010, 00:05
  3. How can I make an object global?
    By Awareness in forum Newbie
    Replies: 10
    Last Post: 27th March 2010, 06:32
  4. writing object to the file(Object Persistance)
    By jjbabu in forum Qt Programming
    Replies: 2
    Last Post: 11th June 2009, 15:28
  5. Open a QMainWindow Object in QDialog Object
    By chuengchuenghq in forum Qt Programming
    Replies: 1
    Last Post: 13th June 2008, 07:33

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.