In this recipe, we will learn how to use another type of high-level method to easily create a multithreading Qt 5 application. We will be using the QRunnable and QThreadPool classes in this recipe.
Working with QRunnable processes
How to do it...
Let's get started by performing the following steps:
- Create a new Qt Widgets Application project and create a new C++ Class called MyProcess, which inherits the QRunnable class.
- Next, open up myprocess.h and add the following headers:
#include <QRunnable>
#include <QDebug>
- Then, declare the run() function, as follows:
class MyProcess : public QRunnable {
public:
MyProcess();
void run();
};
- After that, open up myprocess.cpp and define the run() function: