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 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(scriptObjName, metaObject);
}
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(scriptObjName, metaObject);
}
To copy to clipboard, switch view to plain text mode
Constructor of QScriptValueIterator requires QScriptValue object to be already created.
So, if I modify my code to add
QScriptValueIterator iter (obj);
QScriptValueIterator iter (obj);
To copy to clipboard, switch view to plain text mode
after constructing the obj, the iterator seems to exist outside the scriptengine. Right?
Who implements all these getNext, getPrev etc methods of QScriptValueIterator?
Thanks.
Bookmarks