2

I'm migrating QScriptEngine code over to QJSEngine. Now, I have:

class pars
{
public:
  static QScriptValue PrintMainLog(QScriptContext* c, QScriptEngine* e);
};

QScriptValue pars::PrintMainLog(QScriptContext* c, QScriptEngine* e)
{
    //some actions

    return e->globalObject().property("");
}
...
QScriptEngine engine;
...
engine.globalObject().setProperty("PrintLog",engine.newFunction(pars::PrintMainLog));

So, user can put PrintLog("what ever"); in my application in , for example, QLineEdit and function pars::PrintMainLog will evalute.

Is there are any way to do this with QJSEngine? So, that the user put the same PrintLog("what ever");? The only way I find is here, so the user should put something like Logger.PrintLog("what ever"); where Logger is a class inherited from QObject with PrintLog slot.

Community
  • 1
  • 1
Aksandr
  • 21
  • 2

0 Answers0