How to set dynamic Property for QJSEngine
-
wrote on 12 Jul 2017, 08:59 last edited by NewMoon 7 Dec 2017, 09:05
I would like to add a dynamic properties to the java script function that will be evaluated by a QJSEngine.
QString formula = "_X_*_X_"; //initial value of _X_ is 5 QString jsCode = QString("(function myFunction() {return (%1);})();").arg(formula); QJSValue fun = m_jsengine->evaluate(jsCode); m_jsengine->globalObject().setProperty("_X_",QJSValue(QString("%1").arg(10)); fun.call(); //variable X is not changed to 10
why the set property for the engine does not work here. Does fun.call() will not evaluate the jscode again with the update property? If not then how to tell the engine to take the new value for X instead of the old value.
-
I would like to add a dynamic properties to the java script function that will be evaluated by a QJSEngine.
QString formula = "_X_*_X_"; //initial value of _X_ is 5 QString jsCode = QString("(function myFunction() {return (%1);})();").arg(formula); QJSValue fun = m_jsengine->evaluate(jsCode); m_jsengine->globalObject().setProperty("_X_",QJSValue(QString("%1").arg(10)); fun.call(); //variable X is not changed to 10
why the set property for the engine does not work here. Does fun.call() will not evaluate the jscode again with the update property? If not then how to tell the engine to take the new value for X instead of the old value.
wrote on 17 Jul 2017, 13:13 last edited by NewMoonAny hints on the above question will be helpful for me to proceed.
-
@NewMoon
see QTBUG-38181
It's a known limitation of QJSEngine.
If you can, switch to QScriptEngine (QML).
1/3