我正在使用 Qtcreator 提供的示例并收到此错误...??
void MainWindow::hBtn
{
QScriptEngine e;
QScriptValue fun = e.newFunction(myAdd); // ERROR: No matching function...
e.globalObject().setProperty("myAdd", fun);
QScriptValue result = e.evaluate("myAdd(myNumber, 1)");
}
QScriptValue myAdd(QScriptContext *context, QScriptEngine *engine)
//also tried: QScriptValue MainWindow::myAdd(QScriptContext *context, QScriptEngine *engine) //fails as well with same ERROR
{
QScriptValue a = context->argument(0);
QScriptValue b = context->argument(1);
return a.toNumber() + b.toNumber();
}
示例: http ://harmattan-dev.nokia.com/docs/library/html/qt4/qscriptengine.html
向下滚动到“本机功能”
浏览另一个有问题但也没有解决方案的用户: Using a member function with QScriptEngine::newFunction