Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to set dynamic Property for QJSEngine

How to set dynamic Property for QJSEngine

Scheduled Pinned Locked Moved Unsolved General and Desktop
qjsengineqt5.5qjsvaluescriptqt5.6
3 Posts 2 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NewMoon
    wrote on 12 Jul 2017, 08:59 last edited by NewMoon 7 Dec 2017, 09:05
    #1

    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.

    New Moon....

    N 1 Reply Last reply 17 Jul 2017, 13:13
    0
    • N NewMoon
      12 Jul 2017, 08:59

      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.

      N Offline
      N Offline
      NewMoon
      wrote on 17 Jul 2017, 13:13 last edited by NewMoon
      #2

      Any hints on the above question will be helpful for me to proceed.

      New Moon....

      R 1 Reply Last reply 17 Jul 2017, 13:26
      0
      • N NewMoon
        17 Jul 2017, 13:13

        Any hints on the above question will be helpful for me to proceed.

        R Offline
        R Offline
        raven-worx
        Moderators
        wrote on 17 Jul 2017, 13:26 last edited by
        #3

        @NewMoon
        see QTBUG-38181
        It's a known limitation of QJSEngine.
        If you can, switch to QScriptEngine (QML).

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        1

        2/3

        17 Jul 2017, 13:13

        • Login

        • Login or register to search.
        2 out of 3
        • First post
          2/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved