Quote Originally Posted by coderbob View Post
The script itself is updating the ui, similar to the Calculator example.
That obviously can't be done from a worker thread.

My understanding of scripting is limited, so you are saying I can create an object inside the script pass it back to my c++ as a QScriptValue and then pass that back to the other script as an argument?
Yes, more or less. You can't pass the same object but you can send a copy of the data.

If that is true that would be exactly what I needed, will just need to figure out the creation syntax for an object inside a script and setting its variables and returning it.
There are many ways to do it but you can start with:
javascript Code:
  1. var x = new Object;
  2. x.something = somethingelse;
  3. x.xyz = abc;
  4. return x;
To copy to clipboard, switch view to plain text mode 

Looks like I could do something like
Qt Code:
  1. function foo() {
  2.  
  3. myObject = new Object();
  4.  
  5. myObject.a = 1;
  6. myObject.b = 2;
  7.  
  8. return myObject;
  9. }
To copy to clipboard, switch view to plain text mode 
That should return the myObject as a QScriptValue that I can pass as an argument to the other script?
Yes, that's one possibility. But you can't pass the same value to another engine, you have to copy the data from it to a new object that is bound to the other engine.

Quote Originally Posted by coderbob View Post
In the Calculator example the argument is passed the script like

Qt Code:
  1. QScriptValue ctor = engine.evaluate("Calculator");
  2. QScriptValue scriptUi = engine.newQObject(ui, QScriptEngine::ScriptOwnership);
  3. QScriptValue calc = ctor.construct(QScriptValueList() << scriptUi);
To copy to clipboard, switch view to plain text mode 

This doesn't work
Qt Code:
  1. QScriptValue ctor = engine.evaluate("foo");
  2. QScriptValue scriptObj = engine.newQObject(myScriptValueObject.toObject(), QScriptEngine::ScriptOwnership);
  3. QScriptValue calc = ctor.construct(QScriptValueList() << scriptObj);
To copy to clipboard, switch view to plain text mode 
I cannot find the syntax and playing with the code I am unable to figure out how to pass a QScriptValue as an argument to a script.
JavaScript Object and QObject are two different things. QObjects are modelled as Objects but you can't convert freely between the two (i.e. you can't "cast" Object to QObject).

EDIT: and past that how to pass both the ui and the script object.
You can't reference GUI from non-GUI threads. As for making objects visible to the script, consult the reference manual, there are at least three ways to do it.