How to make Qt work when main thread is busy?

No, you should be doing your calculations in a separate thread. As you already mentioned, there is a work-around available in QCoreApplication::processEvents(), but it sounds like you’re unable to make that work for you.

If you don’t want to have to do all the work of setting up a QThread and moving all your code, you may find that the QtConcurrent::run function is useful – it allows you to run a function asynchronously.

A few pointers: You should try and keep your main (GUI) thread as light as possible. Large amounts of IO or calculations should either be done asynchronously using QtConcurrent::run, or run inside a separate QThread. Depending on the complexity of your code, you may be able to get away with the QtConcurrent method.

Leave a Comment