Use QScript in multithread
-
I am using a public "QScriptEngine" object in multithread,but sometimes ,when I call "evaluate" function to evaluate the script,it returned failure,is it nessary for me to put a lock before call the "QScriptEngine" object functions?
another problem is ,I need call C++ functions in script,I create a C++ class like this:class scriptApi : public QObject
{
Q_OBJECT
public:
explicit
scriptApi(QObject *parent = nullptr);
Q_INVOKABLE QString function1(QString ss);
Q_INVOKABLE QString function2(QString signalName,QString alue);
Q_INVOKABLE QString function3(QString signalName,QString newValue);
Q_INVOKABLE QString function4(QString signalName);
}
is it possiable to use the C++ class in diffreent "QScriptEngine" objects?Do I need put a lock in static C++ functions?
Thanks -
I am using a public "QScriptEngine" object in multithread,but sometimes ,when I call "evaluate" function to evaluate the script,it returned failure,is it nessary for me to put a lock before call the "QScriptEngine" object functions?
another problem is ,I need call C++ functions in script,I create a C++ class like this:class scriptApi : public QObject
{
Q_OBJECT
public:
explicit
scriptApi(QObject *parent = nullptr);
Q_INVOKABLE QString function1(QString ss);
Q_INVOKABLE QString function2(QString signalName,QString alue);
Q_INVOKABLE QString function3(QString signalName,QString newValue);
Q_INVOKABLE QString function4(QString signalName);
}
is it possiable to use the C++ class in diffreent "QScriptEngine" objects?Do I need put a lock in static C++ functions?
Thanks@coderKnight said in Use QScript in multithread:
I am using a public "QScriptEngine" object in multithread
Why? QScriptEngine is not thread safe.
"when I call "evaluate" function to evaluate the script,it returned failure" - does it also happen without multithreading?
"Do I need put a lock in static C++ functions?" - depends what they do.
-
@coderKnight said in Use QScript in multithread:
I am using a public "QScriptEngine" object in multithread
Why? QScriptEngine is not thread safe.
"when I call "evaluate" function to evaluate the script,it returned failure" - does it also happen without multithreading?
"Do I need put a lock in static C++ functions?" - depends what they do.
@jsulm
sorry reply late,QScript works well without multithread,but my project should use QScript in mutithread, I don't know what can I do -
@jsulm
sorry reply late,QScript works well without multithread,but my project should use QScript in mutithread, I don't know what can I do@coderKnight said in Use QScript in multithread:
I don't know what can I do
Make your code thread safe
-
@coderKnight said in Use QScript in multithread:
I don't know what can I do
Make your code thread safe
@jsulm
I create diffrent QScriptEngine ‘s in diffrent thread,but when call C++ function in script,Qt complaint as below:
QScriptValue::call() failed: cannot call function with argument created in a different engine
Why did I get this? -
@jsulm
I create diffrent QScriptEngine ‘s in diffrent thread,but when call C++ function in script,Qt complaint as below:
QScriptValue::call() failed: cannot call function with argument created in a different engine
Why did I get this?@coderKnight said in Use QScript in multithread:
Why did I get this?
The error tells you why.
You are calling a function and passing it arguments which were created in a different thread...