0

I am using an example provide by Qtcreator and getting this error... ??

enter image description here

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

Example: http://harmattan-dev.nokia.com/docs/library/html/qt4/qscriptengine.html

scroll down to "Native Functions"


Looked through another user having problems with no solution either: Using a member function with QScriptEngine::newFunction

Community
  • 1
  • 1
jdl
  • 6,151
  • 19
  • 83
  • 132

2 Answers2

0

Try it with an int for the second parameter. QScriptValue is not int related.

Edit: Ok, just realized that there is another possible combination using QScriptValue, but you may have to pass also an int and make fun a constant.

Hope it helps.

j4nSolo
  • 342
  • 1
  • 14
  • I tried another QTCreator example... issue is with engine.newFunction() ... ?? – jdl Aug 08 '13 at 15:42
  • I can't help you with that. I would have to test it but I can't. Nevertheless, did you try to fulfill the parameter combinations as I suggested? – j4nSolo Aug 09 '13 at 06:25
0

Used as basis: Pass member function pointer in C++

I took the "myAdd" declaration out of the header class... problem solved.

Community
  • 1
  • 1
jdl
  • 6,151
  • 19
  • 83
  • 132