You need to similarly update the videoprocessor.cpp file so that it calls the correct constructor: VideoProcessorThread::VideoProcessorThread(QObject *parent) Also, make sure you include OpenCV headers: #include Ĭlass VideoProcessorThread : public QThread First, make sure that this class inherits QThread by adding the relevant include line and class inheritance, as seen here (just replace QObject with QThread in the header file). Then, choose C++ Class and make sure the combo boxes and checkboxes in the new class wizard look like the following screenshot:Īfter your class is created, you’ll have two new files in your project called videoprocessorthread.h and videoprocessor.cpp, in which you’ll implement a video processor that works in a thread separate from the mainwindow files and GUI threads. #QT UPDATE GUI FROM DIFFERENT THREAD PRO#Now, create a new class called VideoProcessorThread by right-clicking on the project PRO file and selecting Add New from the menu. Also, set their alignment/Horizontal property to AlignHCenter. Make sure to set the objectName property of the label on the left to inVideo and the one on the right to outVideo. We will use these labels to display the original and processed video from the default webcam on the computer: Then, add two label widgets to your mainwindow.ui file, shown as follows. To start with, add an OpenCV framework to this project: Let’s start by creating an example Qt Widgets application in the Qt Creator named MultithreadedCV. First, subclassing and overriding the run method, and second, using the moveToThread function available in all Qt objects, or, in other words, QObject subclasses. We will use this example project to implement multithreading using two different approaches available in Qt for working with QThread classes. This book will help you blend the power of Qt with OpenCV to build cross-platform computer vision applications. This article is an excerpt from the book, Computer Vision with OpenCV 3 and Qt5 written by Amin Ahmadi Tazehkandi. 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. This helps leave the GUI thread (main thread) free and responsive while more intensive processes are handled with the second thread. We will go through this by creating an example project, which processes and displays the input and output frames from a video source using a separate thread. #QT UPDATE GUI FROM DIFFERENT THREAD HOW TO#In today’s tutorial, we will learn how to use QThread and its affiliate classes to create multithreaded applications.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |