tags:

views:

63

answers:

1

I need to process script in separate, non-GUI thread since script calls C++ function that can take very long time to process (seconds). Is it possible to connect QScriptEngineDebugger to my QScriptEngine in non-gui thread?

The problem is - if I put QScriptEngineDebugger in same thread as QScriptEngine (non-gui) than debugger will crash on debug - the code shows that it wants to create it's debug window and such window can be created only in GUI thread. And if i place QScriptEngineDebugger in GUI thread application will crash since QScriptEngine is not thread-safe. Any insights?

+1  A: 

Unless you're prepared to write your own script debugger, there doesn't seem to be a way to run the debugger in a different thread than the engine.

Behind the scenes, QScriptEngineDebugger uses a class called QScriptEngineDebuggerFrontend, which in turn uses a class called QScriptEngineDebuggerBackend, which in turn makes many direct calls to the engine and installs its own agent into the engine. Long story short, there's a lot of coupling between the debugger and the engine.

An alternative is to encapsulate your time-consuming C++ function inside a class which runs the time-consuming function in a background thread and emits a signal when the time-consuming function has completed. Then, connect the signal to a function in your script to process the results. Refer to the following documentation on how to connect signals from your C++ objects to functions in your script:

http://doc.trolltech.com/4.5/qtscript.html#using-signals-and-slots

RA