My embedded project contains a Qt application for the PC which is mainly a simulator for debugging and testing. In the application I can create several widgets which represent either my embedded software or simulate the hardware controlled by the application or can generate external inputs for testing.
I plan to improve the application by adding Lua scripting so that the widgets can be created or controlled from a script. I need an elegant way for single stepping the scripts. I plan scripts like:
createThermometerWidget(10,20,30)
while time < maxTime do
setTemperature(20+time/1000)
pauseSimulation()
time = time + 1
end
The custom function pauseSimulation
should stop the Lua script, enable the Qt event loop to run so that interaction with the software is possible (seting other inputs for example) and after pressing a button the script will continue.
My first idea was to create a separate thread for the Lua execution which will be stopped by pauseSimulation
and released by the button. But Qt widgets cannot be created from non-main thread so that I will have to create all widgets in the main thread and pass all constructor parameters from Lua functions to the main thread.
Is there a more smooth way?