I did it this way:
Qt script code:
function New(This, object)
{
if (!This.objects) This.objects = new Array;
This.objects.push(object);
return object;
}
function objects() { return this.objects; } // Getting objects from C++
...
...
function New(This, object)
{
if (!This.objects) This.objects = new Array;
This.objects.push(object);
return object;
}
function objects() { return this.objects; } // Getting objects from C++
...
box = New(this, new QWidget);
...
To copy to clipboard, switch view to plain text mode
C++ code:
void qkScriptPrivate::updateObjects()
{
Q_Q(qkScript);
QScriptValue objects = engine->globalObject().property("objects");
QScriptValue output = objects.call(scriptValue);
QScriptValueIterator it(output);
while (it.hasNext())
{
it.next();
if (it.value().isQObject()) q->declareObject(it.value().toQObject());
qkPrint("%s : %s", it.name().C_STR, it.value().toString().C_STR);
}
}
void qkScriptPrivate::updateObjects()
{
Q_Q(qkScript);
QScriptValue objects = engine->globalObject().property("objects");
QScriptValue output = objects.call(scriptValue);
QScriptValueIterator it(output);
while (it.hasNext())
{
it.next();
if (it.value().isQObject()) q->declareObject(it.value().toQObject());
qkPrint("%s : %s", it.name().C_STR, it.value().toString().C_STR);
}
}
To copy to clipboard, switch view to plain text mode
Note that you can make it fully transparent by parsing every "new myObject" in the script and replace it by "New(this, new myObject)".
Bookmarks