I am trying to follow the help example. So I created a method in the class which is handling the script engine:
// .h
QScriptValue random(QScriptContext *context, QScriptEngine *engine);
// .h
QScriptValue random(QScriptContext *context, QScriptEngine *engine);
To copy to clipboard, switch view to plain text mode
Then I implemented it (it's just a test):
// .cpp
QScriptValue MyClass::random(QScriptContext *context, QScriptEngine *engine)
{
QScriptValue a = context->argument(0);
return a.toNumber();
}
// .cpp
QScriptValue MyClass::random(QScriptContext *context, QScriptEngine *engine)
{
QScriptValue a = context->argument(0);
return a.toNumber();
}
To copy to clipboard, switch view to plain text mode
When I try to register it:
QScriptValue fun = engine.newFunction(random);
engine.globalObject().setProperty("random", fun);
QScriptValue fun = engine.newFunction(random);
engine.globalObject().setProperty("random", fun);
To copy to clipboard, switch view to plain text mode
I get: /.../../helloscript/myclass.cpp:14: error: no matching function for call to 'QScriptEngine::newFunction(<unresolved overloaded function type>)'
Any idea what's wrong? The only difference I can see from the example is that in my case the function is a class method.
Is it because "global functions" have to be static?
Thanks, chr
Bookmarks