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
QtWS25 Last Chance

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.
  • NewMoonN Offline
    NewMoonN Offline
    NewMoon
    wrote on last edited by NewMoon
    #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....

    NewMoonN 1 Reply Last reply
    0
    • NewMoonN NewMoon

      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.

      NewMoonN Offline
      NewMoonN Offline
      NewMoon
      wrote on last edited by NewMoon
      #2

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

      New Moon....

      raven-worxR 1 Reply Last reply
      0
      • NewMoonN NewMoon

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

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on 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

        • Login

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