I am using qtscript4 and have added some types to the engine.
I registered a function that creates a new object and registered it on the engine with passing ownership to the engine. But the object seems not to get destroyed then leaving scope (at least the debugger does not break at the destructor).
following lines resemble the registration:
QScriptEngine *io_en;
qScriptRegisterMetaType_helper(io_en, metatypeid, marshalfunctions, demarshalfunction, QScriptValue());
QScriptValue ctor = io_en->newFunction(ObjectConstruction<T>::constructMyObject);
QScriptValue metaObject = io_en->newQMetaObject(&QObject::staticMetaObject, ctor);
io_en->globalObject().setProperty(name, metaObject);
ObjectConstruction<T>::constructMyObject
looks like the following:
template <class T>
struct ObjectConstruction
{
static QScriptValue constructMyObject(QScriptContext *, QScriptEngine *engine)
{
T *ob = new T;
return engine->newQObject(ob, QScriptEngine::ScriptOwnership);
}
};
The whole thing seems to work except the destruction. So I think the initial registration seems to be correct. Also the constructor gets called every time I have a var c = new MyObj;
in the code but nothing happens if it goes out of scope.
However the destructors get called at application exit. Maybe javascript has a different opinion of "goes out of scope". But my instantiations of the object are at function scope, so I expected them to be destroyed at the end of the function;
Main.prototype.someTest= function()
{
var c = new MyObj;
c.doSomething();
}
I hope somebody has any hints or suggestions. Thanks in advance.