Threads

The class that offers a thread abstraction in Qt is unsurprisingly named QThread. We start an OS thread by subclassing the QThread class in the following manner:

class MyThread : public QThread 
{
public:
void run()
{
// thread working...
}
};

Then, we instantiate this class and call its start() method. This will start a new OS thread instance and execute the run() method in this new thread's context. The second possibility is not to subclass the QThread but just to call its start() method, which will in turn start its event loop, but more on that later.

Compared to a standard C++ thread class, it must be said that QThread implements thread interruption, which isn't available in C++11 and later.