Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. Unable to get display on QT window if i use pthread pipelining
QtWS25 Last Chance

Unable to get display on QT window if i use pthread pipelining

Scheduled Pinned Locked Moved Unsolved Language Bindings
5 Posts 3 Posters 707 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DhivyaJR
    wrote on 28 Jul 2021, 12:11 last edited by
    #1

    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

    J D 2 Replies Last reply 28 Jul 2021, 12:15
    0
    • D DhivyaJR
      28 Jul 2021, 12:11

      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

      J Offline
      J Offline
      JonB
      wrote on 28 Jul 2021, 12:15 last edited by JonB
      #2

      @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 QThreads. I don't know whether POSIX threads would be suitable/convenient for this instead.

      1 Reply Last reply
      1
      • D DhivyaJR
        28 Jul 2021, 12:11

        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

        D Offline
        D Offline
        DhivyaJR
        wrote on 28 Jul 2021, 12:21 last edited by
        #3

        @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?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 28 Jul 2021, 18:34 last edited by
          #4

          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.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • D Offline
            D Offline
            DhivyaJR
            wrote on 29 Jul 2021, 02:42 last edited by
            #5

            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

            1 Reply Last reply
            0

            3/5

            28 Jul 2021, 12:21

            • Login

            • Login or register to search.
            3 out of 5
            • First post
              3/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved