Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-94195

When interacting between Javascript and C++ JSValue parameters sometimes become uninitialzed



    • Platform/s:


      We have created a scriptable state machine using the QJSEngine but are now running into an issue. We use a script which is called every 500 miliseconds to poll during idle in order to trigger a transition if required. 

      If we keep the system running in idle for a while we keep getting an issue on the call to one of our registered C++ methods. 

      The issue is as follows: We have a method registered to the QJSEngine which has two parameters. The first is a const QString& "key" and the second being a QJSValue "value". Sometimes when we call this method the "value" parameter will be undefined.

      This behaviour seems to be happening at quite random intervals, sometimes after about 5 minutes of running the system, sometimes 20, sometimes 2 hours. I have not been able to figure out what the reason for these random intervals is.

      In my debugging efforts I have changed the call so it's just a string literal coming in from the JS side, doing this still made the bug reproduce. I have also changed the "value" parameter's type to a const QJSValue& and this has only had the effect of changing it from a QJSValue "undefined" to a QJSValue::Int 0.

      I need help figuring out what the cause of this issue is as this call is one of the core elements of our system and we can't miss any of these values.


      Below are snippets from the JS and  C++ code:

      export function CheckWaitFlag()
          // Set the wait flag to false (stop waiting and continue) if MSM has no pending intent states besides the optional current 'stateName' value.
          var size = MSM.GetIntentStackSizeJS();
          var wait = size === 0;
          if (size === 1)
              var intentStatename = MSM.GetIntentStateNameJS();
              wait = !(intentStatename === stateName);
          var flagValue = String(wait ? "true" : "false");
          MSM.SetStoreJS("wait_flag", flagValue);
      int ManagedStateMachine::SetStoreJS(const QString &key, const QJSValue& value)
          //temp variable introduced to help debug rare bug FBLT-7129
          auto temp = value.toVariant();
          QJsonValue asValue = QJsonValue::fromVariant(temp);
          return (int)SetStore(key, asValue);


        No reviews matched the request. Check your Options in the drop-down menu of this sections header.



            qt.team.quick.subscriptions Qt Quick and Widgets Team
            tavandijksioux Thijn van Dijk
            1 Vote for this issue
            6 Start watching this issue



                Gerrit Reviews

                There are no open Gerrit changes