Results 1 to 3 of 3

Thread: QtScript access variable from C++

  1. #1
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default QtScript access variable from C++

    Hey there,

    I'm using QtScript on Qt 4.4.

    I have the following scenario:

    Qt Code:
    1. main.prototype.body = function()
    2. {
    3. box = new qkBox;
    4. box.show();
    5. }
    To copy to clipboard, switch view to plain text mode 
    qkBox is a QObject.

    How can I access this variable from C++ ?
    Can I get an array of all QObjects newed inside the script process ?

    Thanks.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QtScript access variable from C++

    Sometimes I feel like docs reading service, but here it goes: Making a QObject-based Class New-able from a Script
    J-P Nurmi

  3. #3
    Join Date
    Jan 2006
    Posts
    132
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QtScript access variable from C++

    Since you are creating the box as global you should be able to get it after script evaluation somewhat as:

    Qt Code:
    1. QObject* box = engine->globalObject().property("box").toQObject();
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. How can I access public variable parent Form
    By validator in forum Qt Programming
    Replies: 14
    Last Post: 18th December 2008, 21:12
  2. nmake error during .pro compiling
    By mattia in forum Installation and Deployment
    Replies: 5
    Last Post: 18th June 2008, 10:15
  3. main.cpp variable access question
    By MarkoSan in forum Qt Programming
    Replies: 10
    Last Post: 10th March 2008, 20:48

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.