tags:

views:

111

answers:

2

Hello.

QScriptEngine has evaluate() method that can be used to load script, execute it and to run a specified function from already loaded script. But how to clear current script and load a new one? For example, i use evaluate() to load a script from file and then evaluate() to get a script functions and call them. But what can i do to clear current script and load a new one from a different file? Deleting and creating QScriptEngine seems like a solution, but it likes to be created in GUI thread (due to QScriptEngineDebugger) while all script operations are performed in separate thread. So is it any way to clear current script without re-creating QScriptEngine object?

A: 

You could try to set an empty object to http://qt.nokia.com/doc/4.6/qscriptengine.html#setGlobalObject

Maybe that works.

guruz
Global object just defines what 'this' will reference inside script :(. It has no connection to script code itself
Eye of Hell
Did you at least try it? As far as I remember, functions are part of this object.
guruz
QT functions available from script, not script functions.
Eye of Hell
+1  A: 
engine.pushContext();
engine.evaluate("...");
engine.popContext();
engine.pushContext();
engine.evaluate("...");
engine.popContext();

Calling pushContext() before evaluating a script and calling popContext() before evaluating a new script will effectively clear all script data.

Eye of Hell