Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. problem with adding 3 QPixmaps

problem with adding 3 QPixmaps

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 2 Posters 1.1k Views 2 Watching
  • 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.
  • hardikgarg19H Offline
    hardikgarg19H Offline
    hardikgarg19
    wrote on last edited by
    #1

    Hello,
    I have to show video from the camera on Qt GUI. I am reading the camera frames in a different thread and emitting a signal to the main thread whenever there is a new frame.
    On the GUI, I have 3 different QGraphicsview to display the video in 3 different pixel formats. The problem is that, if I use 2 QPixmaps to update the 2 QGraphicsview then the app is running fine. But, if I declare a 3rd QPixmap, the app hangs. Below is the code:

    QGraphicsPixmapItem *Item1, *Item2, *Item3;

    //inside the constructor I am initializing the QGaphicsview and QPixmap

    QImage defaultImg1=QImage(1920,1200,QImage::Format_RGB888);
    QPixmap map1=QPixmap::fromImage(defaultImg1);
    ui->graphicsView1->setScene(new QGraphicsScene(ui->graphicsView1));
    Item1=ui->graphicsView1->scene()->addPixmap(map1);
    //initialize the QGraphicsview with a mono8 image 
    QImage defaultImg2=QImage(1920,1200,QImage::Format_Grayscale8);
    QPixmap map2=QPixmap::fromImage(defaultImg2);
    ui->graphicsView2->setScene(new QGraphicsScene(ui->graphicsView2));
    Item2=ui->graphicsView2->scene()->addPixmap(map2);
    //for third map
    QImage defaultImg3=QImage(1920,1200,QImage::Format_Grayscale8);
    QPixmap map3=QPixmap::fromImage(defaultImg3);
    ui->graphicsView3->setScene(new QGraphicsScene(ui->graphicsView3));
    Item3=ui->DirgraphicsView->scene()->addPixmap(map3);
    

    below is the slot that is connected with a signal from other thread
    void MainWindow::whenNewFrame(const QImage& im1, const QImage& im2, const QImage& im3)
    {
    QPixmap stream1=QPixmap::fromImage(im1);
    QPixmap stream2=QPixmap::fromImage(im2);
    QPixmap stream3=QPixmap::fromImage(im3);

    if (!stream1.isNull())
    {
        Item1->setPixmap(stream1);
        ui->graphicsView1->scene()->update();
    }
    if(!stream2.isNull())
    {
        Item2->setPixmap(stream2);
        ui->graphicsView2->scene()->update();
    }
    if(!stream3.isNull())
    {
        Item3->setPixmap(stream);
        ui->graphicsView3->scene()->update();
    }
    

    }

    After running the app, I am able to see frames on all the 3 graphics view but if I click on the GUI the system hangs. If I remove the third QPixmap then the app works fine. Please let me know what is the problem here and is there any better way to display 3 videos on GUI?

    Thank You

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      I think one way to go about it is to optimise the number of conversions. You have 3 FullHD images that you are processing. Try to minimise the number of data transfer as well as object created.

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

      hardikgarg19H 2 Replies Last reply
      0
      • SGaistS SGaist

        Hi,

        I think one way to go about it is to optimise the number of conversions. You have 3 FullHD images that you are processing. Try to minimise the number of data transfer as well as object created.

        hardikgarg19H Offline
        hardikgarg19H Offline
        hardikgarg19
        wrote on last edited by
        #3

        @SGaist thank you for your reply. Can you please tell me how can I reduce the number of transfers?
        Initially, I was trying to emit only one image and converting it into the slot (whenNewFrame). But, the "whenNewFrame" function parameter QImage is const QImage. So, I can not convert this image inside the function and I can not change the parameter type as well. If I remove the const from the function parameters then I am getting errors.

        1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          I think one way to go about it is to optimise the number of conversions. You have 3 FullHD images that you are processing. Try to minimise the number of data transfer as well as object created.

          hardikgarg19H Offline
          hardikgarg19H Offline
          hardikgarg19
          wrote on last edited by
          #4

          @SGaist I am getting below message in Qt:
          Qimage: out of memory, returning null image

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Sounds like you either have a memory leak somewhere in your code or you are not consuming your data fast enough.

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

            hardikgarg19H 1 Reply Last reply
            0
            • SGaistS SGaist

              Sounds like you either have a memory leak somewhere in your code or you are not consuming your data fast enough.

              hardikgarg19H Offline
              hardikgarg19H Offline
              hardikgarg19
              wrote on last edited by
              #6

              @SGaist yes, the problem was with data consuming rate. I have solved it now by using "Qt::BlockingQueuedConnection" in my connection between worker and GUI thread.
              Thank you so much for your help.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Aren't you loosing images doing so ?

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

                hardikgarg19H 1 Reply Last reply
                0
                • SGaistS SGaist

                  Aren't you loosing images doing so ?

                  hardikgarg19H Offline
                  hardikgarg19H Offline
                  hardikgarg19
                  wrote on last edited by
                  #8

                  @SGaist No, I am getting all the frames.

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Nice then.

                    Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that forum users may know a solution has been found :)

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

                    hardikgarg19H 1 Reply Last reply
                    0
                    • SGaistS SGaist

                      Nice then.

                      Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that forum users may know a solution has been found :)

                      hardikgarg19H Offline
                      hardikgarg19H Offline
                      hardikgarg19
                      wrote on last edited by
                      #10

                      @SGaist done
                      Thank you

                      1 Reply Last reply
                      0

                      • Login

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