Important: Please read the Qt Code of Conduct -

Qlabel in video not showing - Raspberry pi 4 Opencv 4.1.0

  • I installed Opencv 4.1.0 and Qt Creator on Rpi 4. I created a gui with a button and a label. When the button is clicked, I want the video to play in the label. The codes I use for this are:
    VideoCapture cap(“/home/users/video.mp4”);
         cout << "Error opening video stream or file" << endl;
         return -1;

    	Mat frame;
    	cap >> frame;
    	if (frame.empty())


    	Qimage img = Qimage((uchar*), frame.cols, frame.rows, frame.step, Qimage::Format_RGB888);
    	char c = (char) waitKey(25);

    No video is shown in Label. But imshow (“Frame”, frame); When I add the command line, the video is displayed in the label.
    How can I show the video in qlabel ?

  • Lifetime Qt Champion


    You are blocking the event loop with your tight loop as well as your wait key.

    Use a Timer that will read your file at regular interval since you anyway wait for 25ms.

  • ui->label->repaint()

Log in to reply