Unable to get display on QT window if i use pthread pipelining
-
@DhivyaJR said in Unable to get display on QT window if i use pthread pipelining:
pthread pipline architecture
I don't know exactly what you are trying to do. But be aware that all Qt UI operations must be performed in the one main UI thread. If running other threads they will need to use the Qt signal/slot mechanism to communicate data to the main UI thread for it to display.
Threading like this is usually done with Qt's
QThread
s. I don't know whether POSIX threads would be suitable/convenient for this instead. -
@DhivyaJR said in Unable to get display on QT window if i use pthread pipelining:
I am trying to build a project in Qt with pthread pipline architecture.
my archietecture consist of 3 threads 1.Capture 2.Process 3.Display
all the above 3 will run in parallel
here is my sample code pipeline.cpp
#include "mainwindow.h" #include "pipeline.h" #include <QMainWindow> #include<QDebug> #include "ui_mainwindow.h" void *capture_function( void *ptr ) { qDebug()<<"Capture Thread"; while (1) { //read image from video } //queue push for next thread in pipeline } void *process_function( void *ptr ) { qDebug()<<"Process Thread"; while (1) { //process the captured image } //queue push for next thread in pipeline } void *display_function( void *ptr ) { qDebug()<<"Display Thread"; while (1) { img1 = QImage(processedValue->rgb_frame_ptr[0],Image_Width,Image_Height,QImage::Format_RGB888); //free queue memory } }
main_window.cpp
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); styleWidgetCompents(); timer_offline = new QTimer(this); QObject::connect(timer_offline, SIGNAL(timeout()), this, SLOT(test())); } void MainWindow::on_play_clicked() { timer_offline->start(100); } void MainWindow::test() { qDebug()<<"Inside test"; ui->display1_offline->setPixmap(QPixmap::fromImage(img1)); }
I have used the timer signal to call "test()" slot, and I am expecting a display every 100 msec. But the "test" function is not getting executed and unable to get the display. But if I save the image at end of display thread the images are getting saved properly.
What I could understand is the control is not coming out of threads,so that Qt UI is not accessible Can someone please help me to fix this issue?
-
Hi and welcome to devnet,
There's not reason here to use pure posix threads.
Use QThread to do you pipeline but there's no need for the GUI to be in a separate thread.
To get started, take a look at the Mandelbrot example.
Note that depending on the time it takes to do your processing you might not even need that many threads.
-
Thank you for the reply .
I am new to Qthread and comfortable with pthread, that is the reason behind I used it in my code.
Let me go through the link and use qthread.
Thank you for the sugesstion.If possible Please share me some tutorial links for qthreads which helps to build pipeline
Thank you,
Dhivya JR