Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QtScript: how to reload current script?

Tags:

qt

qtscript

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?

like image 633
grigoryvp Avatar asked Jan 23 '23 18:01

grigoryvp


1 Answers

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.

like image 108
grigoryvp Avatar answered Feb 01 '23 05:02

grigoryvp