Chapter 17. Multithreading
Working with ThreadsCommunicating with the GUI ThreadUsing Qt's Classes in Non-GUI Threads
Chapter 7 (Event Processing) provides some solutions to this problem. Multithreading is another solution.In a multithreaded Qt application, the GUI runs in its own thread and the processing takes place in one or more other threads. This results in applications that have responsive GUIs even during intensive processing. Another benefit of multithreading is that on multiprocessor machines different threads may be executed simultaneously on different processors, resulting in better performance.In this chapter, we will start by showing how to subclass QThread and how to use QMutex, QSemaphore, and QWaitCondition to synchronize threads. Then we will see how to communicate with the GUI thread from non-GUI threads while the event loop is running, and round off with a review of which Qt classes can be used in non-GUI threads and which cannot.Multithreading is a large topic with many books devoted exclusively to the subject. Here, it is assumed that you already understand the fundamentals of multithreaded programming; the focus is on explaining how to develop multithreaded Qt applications rather than on the subject of threading itself.