Important: Please read the Qt Code of Conduct -

problem with adding 3 QPixmaps

  • 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));
    //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));
    //for third map
    QImage defaultImg3=QImage(1920,1200,QImage::Format_Grayscale8);
    QPixmap map3=QPixmap::fromImage(defaultImg3);
    ui->graphicsView3->setScene(new QGraphicsScene(ui->graphicsView3));

    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())


    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

  • Lifetime Qt Champion


    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.

  • @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.

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

  • Lifetime Qt Champion

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

  • @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.

  • Lifetime Qt Champion

    Aren't you loosing images doing so ?

  • @SGaist No, I am getting all the frames.

  • Lifetime Qt Champion

    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 :)

  • @SGaist done
    Thank you

Log in to reply