What I am looking for is something like this:
QScriptValue getter(QScriptContext* context, QScriptEngine* engine)
{
QString property
= context
->getProperty
();
// this is what I am looking for if(property == "id")
return id;
else if(property == "name")
return name;
else if
context->throwError("There is no property like that!");
}
QScriptValue getter(QScriptContext* context, QScriptEngine* engine)
{
QString property = context->getProperty(); // this is what I am looking for
if(property == "id")
return id;
else if(property == "name")
return name;
else if
context->throwError("There is no property like that!");
}
To copy to clipboard, switch view to plain text mode
And so you could just do this:
object.setProperty("id", engine.newFunction(getter), QScriptValue::PropertyGetter);
object.setProperty("name", engine.newFunction(getter), QScriptValue::PropertyGetter);
object.setProperty("id", engine.newFunction(getter), QScriptValue::PropertyGetter);
object.setProperty("name", engine.newFunction(getter), QScriptValue::PropertyGetter);
To copy to clipboard, switch view to plain text mode
So that you only have to make one getter for two properties.
I hope you understand what I mean!
Gillis
Bookmarks