Nominate our 2022 Qt Champions!

QtScript problem: corrupted Javascirpt variables

  • I have tester device which a user can be control by running a Javascript.

    The device is continuously sending measurement data to the program which updates the corresponding variables of the script engine.

    Moreover, in the engine via some custom functions the device is controller.

    Unfortunately, it seems that sometimes (not always) the variables defined in the engine become corrupted.
    For example,
    QScriptValue own_function(QScriptContext *context, QScriptEngine *engine)
    QString Text;

    Text = context->argument(0).toString();
    const QString ret = do_some_processing( Text);
    return QScriptValue( ret );

    implements the function in C++. In Javascript, I have
    for (i=1;i<11;i++)
    x = x+5;
    own_function("value = " + x);

    And sometimes, the variable Text contains invalid string, for example "value = 12[o".

    Some additional info: script engine runs concurently:
    connect(&watcher, SIGNAL(finished()), this, SLOT(onEvalFinished()));
    future = QtConcurrent::run(scriptEngine, &QScriptEngine::evaluate, script_code);

    In this project Qt 4.8 is used.

    Do you have any idea how it can go wrong?
    Or maybe, is there any rule how I can update a Javascript variable during running of a script engine?


Log in to reply