Results 1 to 2 of 2

Thread: QtScript. How to add created object to script?

  1. #1
    Join Date
    Oct 2009
    Location
    Russia, South Ural, Chelyabinsk
    Posts
    42
    Thanks
    1
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

  2. #2
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QtScript. How to add created object to script?

    Qt Code:
    1. engine->newQObject(new MyQObject(), QScriptEngine::ScriptOwnership);
    To copy to clipboard, switch view to plain text mode 
    Probably you will want to call the constructor from script as well?

    Qt Code:
    1. c++:
    2. QScriptValue myQObjectConstructor(QScriptContext *context, QScriptEngine *engine)
    3. {
    4. // let the engine manage the new object's lifetime.
    5. return engine->newQObject(new MyQObject(), QScriptEngine::ScriptOwnership);
    6. }
    7.  
    8. scripting->globalObject().setProperty("MyQObject", scripting->newFunction(myQObjectConstructor));
    9.  
    10. script:
    11. ..
    12. var q = new MyQObject();
    13. ..
    To copy to clipboard, switch view to plain text mode 

    Carefully read through http://doc.trolltech.com/latest/scripting.html

    It took me several times :->

    Johannes

Similar Threads

  1. Replies: 4
    Last Post: 11th May 2010, 17:33
  2. Replies: 1
    Last Post: 19th February 2010, 11:02
  3. Replies: 4
    Last Post: 9th February 2010, 17:08
  4. QtScript: how to reload current script?
    By eyeofhell in forum Qt Programming
    Replies: 7
    Last Post: 12th January 2010, 10:28
  5. Replies: 2
    Last Post: 20th September 2009, 02:52

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.