TorAn
2nd December 2012, 15:57
I don't understand how to implement QScriptValueIterator. I want to implement a script object that has some properties and also allows for java-style iteration in the script text.
Documentation (http://doc.qt.digia.com/qt/qscriptvalue.html#details) states:
"If you want to iterate over the properties of a script object, use the QScriptValueIterator class."
My code looks like this:
static void registerWithScript(const char* scriptObjName, QScriptEngine& scriptengine)
{
T* t = new T();
QScriptValue obj = scriptengine.newQObject(t, QScriptEngine::ScriptOwnership);
scriptengine.setDefaultPrototype(qMetaTypeId<T>(),obj);
QScriptValue ctor = scriptengine.newFunction(objectConst);
QScriptValue metaObject = scriptengine.newQMetaObject(&QObject::staticMetaObject, ctor);
scriptengine.globalObject().setProperty(scriptObjN ame, metaObject);
}
Constructor of QScriptValueIterator requires QScriptValue object to be already created.
So, if I modify my code to add
QScriptValueIterator iter (obj);
after constructing the obj, the iterator seems to exist outside the scriptengine. Right?
Who implements all these getNext, getPrev etc methods of QScriptValueIterator?
Thanks.
Documentation (http://doc.qt.digia.com/qt/qscriptvalue.html#details) states:
"If you want to iterate over the properties of a script object, use the QScriptValueIterator class."
My code looks like this:
static void registerWithScript(const char* scriptObjName, QScriptEngine& scriptengine)
{
T* t = new T();
QScriptValue obj = scriptengine.newQObject(t, QScriptEngine::ScriptOwnership);
scriptengine.setDefaultPrototype(qMetaTypeId<T>(),obj);
QScriptValue ctor = scriptengine.newFunction(objectConst);
QScriptValue metaObject = scriptengine.newQMetaObject(&QObject::staticMetaObject, ctor);
scriptengine.globalObject().setProperty(scriptObjN ame, metaObject);
}
Constructor of QScriptValueIterator requires QScriptValue object to be already created.
So, if I modify my code to add
QScriptValueIterator iter (obj);
after constructing the obj, the iterator seems to exist outside the scriptengine. Right?
Who implements all these getNext, getPrev etc methods of QScriptValueIterator?
Thanks.