There is no "oFnStart" object in our test program. Could you add it there and post the code again?
Complete code of latest test, based on your proposals. main.cpp:
#include <QtCore/QCoreApplication>
#include <QThread>
#include "main.h"
void MyThread::run()
{
m_interpreter = new QScriptEngine(this);
exec();
delete m_interpreter;
m_interpreter = 0;
}
void MyThread::test()
{
if(!m_interpreter) return;
QString sScript
= "function OnStart() { var a = [ [ 0 ] ]; " "for( var i = 0; i < 3; i ++ ) { for( var j = 0; j < 100; j ++ ) "
"{ \"a\" + a[ 0 ][ 0 ]; } } }";
m_interpreter->evaluate( sScript );
QScriptValue oFnStart = m_interpreter->evaluate( "OnStart" );
Q_ASSERT( oFnStart.isFunction() );
oFnStart.call();
}
int main(int argc, char *argv[])
{
MyThread oThread;
oThread.moveToThread( & oThread );
oThread.start();
App app;
QObject::connect( & app,
SIGNAL( ScriptTest
() ),
& oThread,
SLOT( test
() ) );
app.startTimer( 50 );
return a.exec();
}
#include <QtCore/QCoreApplication>
#include <QThread>
#include "main.h"
void MyThread::run()
{
m_interpreter = new QScriptEngine(this);
exec();
delete m_interpreter;
m_interpreter = 0;
}
void MyThread::test()
{
if(!m_interpreter) return;
QString sScript = "function OnStart() { var a = [ [ 0 ] ]; "
"for( var i = 0; i < 3; i ++ ) { for( var j = 0; j < 100; j ++ ) "
"{ \"a\" + a[ 0 ][ 0 ]; } } }";
m_interpreter->evaluate( sScript );
QScriptValue oFnStart = m_interpreter->evaluate( "OnStart" );
Q_ASSERT( oFnStart.isFunction() );
oFnStart.call();
}
void App::timerEvent( QTimerEvent* ) { ScriptTest(); }
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
MyThread oThread;
oThread.moveToThread( & oThread );
oThread.start();
App app;
QObject::connect( & app, SIGNAL( ScriptTest() ), & oThread, SLOT( test() ) );
app.startTimer( 50 );
return a.exec();
}
To copy to clipboard, switch view to plain text mode
main.h
#pragma once
#include <QObject>
#include <QScriptEngine>
#include <QThread>
Q_OBJECT
public:
MyThread
() : QThread() { m_interpreter
= 0;
} void run();
public slots:
void test();
private:
QScriptEngine *m_interpreter;
};
{
Q_OBJECT;
signals: void ScriptTest();
};
#pragma once
#include <QObject>
#include <QScriptEngine>
#include <QThread>
class MyThread : public QThread {
Q_OBJECT
public:
MyThread() : QThread() { m_interpreter = 0; }
void run();
public slots:
void test();
private:
QScriptEngine *m_interpreter;
};
class App : public QObject
{
Q_OBJECT;
signals: void ScriptTest();
protected: void timerEvent( QTimerEvent* );
};
To copy to clipboard, switch view to plain text mode
Please include the code of the evaluated script
Do you means the text inside evaluate call()? It's in code:
QString sScript
= "function OnStart() { var a = [ [ 0 ] ]; " "for( var i = 0; i < 3; i ++ ) { for( var j = 0; j < 100; j ++ ) "
"{ \"a\" + a[ 0 ][ 0 ]; } } }";
m_interpreter->evaluate( sScript );
QString sScript = "function OnStart() { var a = [ [ 0 ] ]; "
"for( var i = 0; i < 3; i ++ ) { for( var j = 0; j < 100; j ++ ) "
"{ \"a\" + a[ 0 ][ 0 ]; } } }";
m_interpreter->evaluate( sScript );
To copy to clipboard, switch view to plain text mode
and the result of QScriptValue::isFunction().
It's always true, assert never trigger:
Q_ASSERT( oFnStart.isFunction() );
Q_ASSERT( oFnStart.isFunction() );
To copy to clipboard, switch view to plain text mode
Bookmarks