Question

I have an application in which simulation and visualization both are important. Currently, my visualization and simulation is done in the same loop (i.e. QT even loop). I would like to create a separate loop for simulation. What are the best ways creating another loop with out effecting the functionality of the Singal/Slot etc.?

Was it helpful?

Solution

The simplest answer would be that new QThread provides thread-local event loop, thus you can move your simulation into new QThread (see Per-thread event loop). However, without more details about your simulation I can only assume it will meet your needs.

OTHER TIPS

There's no point to multiple event loops in a single-threaded application.

If you have multiple threads, then if you want to use events in those threads, the threads must have an event loop running in them.

Thus your problem has solved itself, in a way. Simply use a separate simulation thread, and move the simulation QObject(s) to it.

Note that QThread is a bastard child and is not a proper C++ class since it can't be always safely destructed. Use a safe replacement.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top