PDA

View Full Version : How to connect QScriptEngineDebugger to QScriptEngine in separate thread?



eyeofhell
15th January 2010, 09:20
Hello.

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 multithread safe :(. Any insights?

wysota
15th January 2010, 13:06
I don't think that's possible. I'd suggest to process the script in the main thread and use QScriptEngine::setProcessEventsInterval() to prevent GUI from blocking.

eyeofhell
15th January 2010, 13:26
As i mentioned, script calls back C++ code with functions that have very long execution time, so processing interval does nothing - it will not interrupt C++ function execution :(. Maybe it's possible to decouple script itself and execution of C++ functions somehow?

wysota
15th January 2010, 16:01
Is the C++ function Qt code too? You could call processEvents() there as well... Using a script debugger in a non-gui thread simply won't work as the engine is not thread-safe.

eyeofhell
16th January 2010, 10:08
Thanks. It seems that processEvents() inside Qt C++ code is the only solution to use script debugger for long executing script :(.

wysota
16th January 2010, 10:17
You can also make your C++ call asynchronous. The contents of it can run in a separate thread while the script itself (and thus the main application) continues execution.