PDA

View Full Version : QT Scripting - Native Functions



gabon
17th May 2010, 07:52
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);

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();
}


When I try to register it:


QScriptValue fun = engine.newFunction(random);
engine.globalObject().setProperty("random", fun);

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

wysota
17th May 2010, 08:40
Your "random" is not a function but a class member method. Make it a standalone function or make it static.