January 2019
Intermediate to advanced
384 pages
11h 50m
English
A thread pool preallocates a number of worker threads and then allows the user to use them for their run computations. Each Qt application has one global QThreadPool object, which can be accessed by calling globalInstance(). QThreadPool allows running instances of QRunnable (also known as tasks) by calling QThreadPool::start(), as in the following example:
class DoSomethingTask : public QRunnable{ void run() override { ... do something }};auto taskPtr = new DoSomethingTask ();QThreadPool::globalInstance()->start(taskPtr);
Note that QThreadPool will take ownership of the task and will delete it automatically on completion. You can disable this by using the QRunnable::setAutoDelete() function. We can control the number of threads ...
Read now
Unlock full access