Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QScript: How to pass in an array of objects to a javascript function
Forum Updated to NodeBB v4.3 + New Features

QScript: How to pass in an array of objects to a javascript function

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 942 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DBoosalis
    wrote on last edited by
    #1

    I want to create an array of object and pass them into Qt's Javascipt engine. I have no problem passing in an object itself, and have had no problem passing in an array of simple objects such as strings. But trying to pass an array of semi-simple objects has been elusive to me. Here is what I have

    @QString function;

    function.append("print(Person.name + ' age:' + Person.age);");
    function.append("print(People[0].name);"); // how to print this out ?

    QScriptValue sv = engine.newObject();
    QScriptValue svA = engine.newArray(2);

    QScriptValue person1;
    person1.setProperty(name,"Larry");
    person1.setProperty("age",32);
    QScriptValue person2;
    person2.setProperty(name,"Marry");
    person2.setProperty("age",29);

    QScriptValue v1;
    sv.setProperty("name","matt");
    sv.setProperty("age",24);

    engine.globalObject().setProperty("Person",sv);
    engine.globalObject().setProperty("People",svA);
    searchFunction = engine.evaluate(function);@

    I only get the first print out.
    matt age:24

    Must be a simple thing , but I have tried all sorts of permutations, with no success. I hope someone can please tell me the correct way to pass in an array of objects to a javascript function.

    I am using Qt 5 with the script module by the way

    Thanks
    David

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved