The QRunnable class works hand-in-hand with the QThreadPool class, which manages a collection of threads. The QThreadPool class automatically manages and recycles individual QThreads objects to avoid creating and destroying threads too frequently, which helps in reducing computing costs.
To use QThreadPool, you must sub-class the QRunnable object and implement the virtual function called run(). By default, QThreadPool will automatically delete the QRunnable object when the last thread exits the run function. You can change this behavior by calling setAutoDelete() to change the autoDelete variable to false.
By default, threads that are unused for more than 30 seconds will expire. You can change this duration by calling setExpiryTimeout() before the thread is running. Otherwise, it will not have any effect on the timeout setting.
You can also set the maximum number of threads that can be used by calling setMaxThreadCount(). To get the total number of current active threads, simply call activeThreadCount().