Results 1 to 5 of 5

Thread: QScript design questions

  1. #1
    Join Date
    Mar 2011
    Posts
    21
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default QScript design questions

    Hi,

    Following situation:

    We have a C++ data structure which is a tree of nodes. Each node has a name and represents a double value or double array or a child list of nodes. The tree is quite large. There is one C++ funtion "F" which operates on a part of the tree. We would like to have a scripting interface for it using QScript. I have a couple of questions where I only need some pointers to the right design and the right classes/examples since right now I am not even able to ask the right questions.

    In JavaScript we would like to something like

    Tree.a.b = 3.2
    Tree.f.s.a = 4
    F() or even better F(Tree.f)
    print(Tree.f.s.b)
    Tree.f.s.a = 4
    F(Tree.f)
    print(Tree.f.s.b)
    ...

    1) First we have to copy the tree somehow to script variables? What is the strategy and which of the QT-examples ist most approbiate?
    2) To call C++-"F" from javascript-"F" is quite clear.
    3) With a call to JavaScript F(Tree.f) can I change Tree.f or is this read only?
    4) After Tree.f.s.a = 4, how can I copy data from JavaScript to C++-Tree without having to copy all data? Is there some signal when a JavaScript variables changes or somethin similar?
    5) After calling F we have marks in the C++Tree so that we know in principal which nodes to update back to Javascript.

    Points 3/4 is most unknown for me.

    Thanks for your help!

    Thomas

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QScript design questions

    Quote Originally Posted by ctgrund View Post
    1) First we have to copy the tree somehow to script variables? What is the strategy and which of the QT-examples ist most approbiate?
    You can either "copy" the data into new objects or you can expose your existing objects in form of ecmascript api. It mainly depends if you intend to modify those objects from the script. If not, copying should be easier - just create a bunch of objects (using newObject()) and assign properties to them.

    3) With a call to JavaScript F(Tree.f) can I change Tree.f or is this read only?
    It depends on how you solve issue #1 and also what the function signature is.

    4) After Tree.f.s.a = 4, how can I copy data from JavaScript to C++-Tree without having to copy all data?
    You can either resynchronize the two object groups manually or you just wrap your real objects into script api as said in the beginning.

    Is there some signal when a JavaScript variables changes or somethin similar?
    No.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2011
    Posts
    21
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QScript design questions

    Quote Originally Posted by wysota View Post
    You can either "copy" the data into new objects or you can expose your existing objects in form of ecmascript api. It mainly depends if you intend to modify those objects from the script. If not, copying should be easier - just create a bunch of objects (using newObject()) and assign properties to them.
    I feel that I need the second case because I would like to modify C++ Objects from ecmascript. Can you give me some keywords (in form of QT class or method names or examples or some small skeleton) how I "expose your existing objects in form of ecmascript api". I just need a starting point.

    Thank you!

    Thomas

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QScript design questions

    You can start here: Making a C++ object available to scripts written in QtScript. Also have a look at QScriptable and QScriptClass. The "Default Prototypes" example might be something useful for you.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    ctgrund (24th March 2011)

  6. #5
    Join Date
    Mar 2011
    Posts
    21
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QScript design questions

    This was exactly the kind of link I was looking for.

    Thanks!

Similar Threads

  1. Can't get qScript to work
    By lni in forum Qt Programming
    Replies: 1
    Last Post: 18th September 2010, 21:49
  2. How to use QScript?
    By lni in forum Qt Programming
    Replies: 5
    Last Post: 2nd August 2010, 14:36
  3. QScript workbench in 4.3
    By jh in forum Qt Programming
    Replies: 3
    Last Post: 29th October 2009, 13:53
  4. Replies: 3
    Last Post: 5th October 2008, 23:41
  5. application design questions
    By nikita in forum Qt Programming
    Replies: 6
    Last Post: 28th August 2006, 00:35

Tags for this Thread

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.