Results 1 to 2 of 2

Thread: scriptengine

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2010
    Posts
    38
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3

    Question scriptengine

    Qt Code:
    1. QScriptEngine engine;
    2. QScriptValue o = engine.globalObject();
    3. QScriptValue oo;
    4. QScriptValue o1;
    5.  
    6. o1 = o.property("org");
    7. if (!o1.isValid()) {
    8. o1 = engine.newObject();
    9. o.setProperty("org", o1);
    10. }
    11.  
    12. o1= o.property("org.math");
    13. if (!o1.isValid()) {
    14. o1 = engine.newObject();
    15. o.setProperty("math", o1);
    16. }
    17.  
    18. engine.evaluate("org.sum = function Math_sum(a){ return 123456; }");
    19. engine.evaluate("org.math.sum = function Math_sum(a){ return 654321; }");
    20. engine.evaluate("var r = org.sum(12); print(r); ");
    21. engine.evaluate("var r1 = org.math.sum(12); print(r1); ");
    To copy to clipboard, switch view to plain text mode 

    output is: 123456

    I have try this way too:
    Qt Code:
    1. QScriptValue o = engine.globalObject();
    2. QScriptValue oo;
    3. QScriptValue o1;
    4.  
    5. o1 = o.property("org");
    6. if (!o1.isValid()) {
    7. o1 = engine.newObject();
    8. o.setProperty("org", o1);
    9. }
    10.  
    11. QScriptValue o2;
    12. o2= o1.property("math");
    13. if (!o2.isValid()) {
    14. o2 = engine.newObject();
    15. o.setProperty("math", o2);
    16. }
    To copy to clipboard, switch view to plain text mode 

    but the outout still is 12345.

    If i want excute function org.math.sum(), how should I set the property.

  2. #2
    Join Date
    Jun 2010
    Posts
    38
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3

    Default Re: scriptengine

    resolve it out ..

    just look at the codes.

    Qt Code:
    1. QScriptEngine engine;
    2. QScriptValue o = engine.globalObject();
    3. QScriptValue oo;
    4. QScriptValue o1;
    5. QScriptValue o2;
    6.  
    7. o1 = o.property("org");
    8. if (!o1.isValid()) {
    9. o1 = engine.newObject();
    10. o.setProperty("org", o1);
    11. }
    12.  
    13.  
    14. o2= o.property("org").property("math");
    15.  
    16. if (!o2.isValid()) {
    17. o2 = engine.newObject();
    18.  
    19. o1.setProperty("math", o2);
    20. }
    21.  
    22. engine.evaluate("org.sum = function Math_sum(){ return 123456; }");
    23. engine.evaluate("org.math.sum = function Math_sum(){ return 654321; }");
    24. engine.evaluate("var r = org.sum(); print(r); ");
    25. engine.evaluate("var r1 = org.math.sum(); print(r1); ");
    To copy to clipboard, switch view to plain text mode 

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
  •  
Qt is a trademark of The Qt Company.