Low-level multithreading using QThread
In this section, we will learn how to use QThread
and its classes to create multithreaded applications. We will go through this by creating an example project, which processes and displays the input and output from a video source using a separate thread. This helps leave the GUI thread (main thread) free and responsive while more intensive processes are handled with the second thread. As it was mentioned earlier, we will focus mostly on the use cases common to computer vision and GUI development; however, the same (or a very similar) approach can be applied to any multithreading problem.
We will use this example project to implement multithreading using two different approaches available in Qt for working with QThread
classes. First, subclassing and overriding the run method, and second, using the moveToThread
function available in all Qt objects, or, in other words, QObject
subclasses.
Subclassing QThread
Let's start by creating an example Qt Widgets...