[Qt-interest] How to copy a QScriptValue ?
mario
dodiesis at gmail.com
Fri Jan 7 17:57:56 CET 2011
Hi all.
I need to copy a js object ( created in a QtScript ) and recreate it
in another QScriptEngine.
The goal is to have a "shared object" among many QScriptEngines.
Thread safety is not a problem in my case.
For example in a script in a first QScriptEngine I could have:
var xyz = new Object();
xyz.arr = new Array();
xyz.arr[1] = 31;
xyz.arr[2] = 32;
xyz.arr[3] = 33;
xyz.arr[4] = 34;
and later in a second QScriptEngine I should access at xyz.arr array,
and maybe add some other stuff in this:
xyz.stuff = new Date();
I tried with QScriptValue::toVariant() anb QScriptValue::newVariant()
, but it does not work:
To retreive the value:
QScriptValue globalShared = global.property("xyz");
QVariant m_sSharedDatas = globalShared.toVariant();
To recreate the value:
QScriptEngine engine;
QScriptValue sharedVal = engine.newVariant ( m_sSharedDatas );
engine.globalObject().setProperty("xyz", globalShared);
I can see the sSharedDatas filled with all my values, but when in the
second engine I try to access to the new xyz variable, I always have
"undefined".
What am I missing?
Tnx all,
Mario
More information about the Qt-interest-old
mailing list