Nominate our 2022 Qt Champions!

[SOLVED] Using Qt and OpenCV to display videos

  • Hi guys,

    I am using Qt and openCV to display some videos.
    Everything works fine except that the video displays very fast! I thought it could be a problem with the frame rate definition in openCV, but it is not. Also tried to set a larger interval in the timer (QTimer), but none of this works.

    Here is my code:
    void MainWindow::on_btnLoad_clicked()
    filename = ui->lnFile->text();
    QByteArray ba = filename.toLocal8Bit();
    string name =;
    inputVideo = new VideoCapture(name.c_str());

    inputVideo->set(CV_CAP_PROP_FPS, 27.5);
    if (inputVideo->isOpened() == false){
        ui->txtInfo->appendPlainText("Problem loading file!");
    } else
    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(DisplayVideo()));


    void MainWindow::DisplayVideo(){

    *inputVideo >> img;
    QImage qImage((uchar*), img.cols, img.rows, img.step, QImage::Format_RGB888);

    Can anyone help me, please?

    Thank you in advance,

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Please enclose your code with coding tags, it will make readable.

    Your timer (which I supposed is connected to DisplayVideo) has a timeout of 1 ms, isn't that a bit fast ?

    By the way, your connect statement doesn't make any sense, could please correct it so we know what should happen ?

    Hope it helps

  • Hello and thank you very much for your reply!
    How do I change my timer speed? timeout doen't have any parameter changing. (As long as I can see in the function description.)
    Sorry, but I am very new at Qt, so I just adapted the code in this video to my problem:
    So I don't really know how my connect statement should look like...
    Thank you, in advance.

  • Ok, ok! I just figured out how to make things work!
    Just changed the "start" input value and now it is working fine!

  • Lifetime Qt Champion

    Nice you found out !

    Don't forget to update the thread's title so that other forum users may know that it has been solved :)

Log in to reply