QVideoProbe control destroyed while it's still being referenced

  • I created a QCamera, and a QVideoProbe, which will allow me to access each frame of the video. The problem is that every time I close the app, I get this message in Qt Creator: 'QVideoProbe control destroyed while it's still being referenced!!!'.

    I'm using Qt 5.11 on Windows 8.1. My compilator is MSVC 2015 (32-bit).

    Here's my code:

            QMessageBox::critical(this, "Error", "No camera is available");
        m_camera = new QCamera;
        m_videoProbe = new QVideoProbe(this);
            QMessageBox::critical(this, "Error", "setSource");
        connect(m_videoProbe, SIGNAL(videoFrameProbed(QVideoFrame)), this, SLOT(cameraFrameProbed(QVideoFrame)));
        // For now the slot 'cameraFrameProbed' is empty

    What did I miss?

  • Lifetime Qt Champion


    Did you try to explicitly stop the camera before quitting the application ?

  • Hello SGaist,

    Thank you for your reply.
    Yes, the result is the same, the message appears once the QVideoProbe gets destroyed.

  • Problem solved! I replaced this line:

    m_videoProbe = new QVideoProbe(this);

    with this one:

    m_videoProbe = new QVideoProbe;

    Could somebody explain me what was wrong with the first line and why did I get this message?
    Again, thank you for your help SGaist.

    EDIT: The previous solution has a memory leak! Here's the correct one:

    I forgot to mention the parent of the QCamera when constructing it.

    So the code becomes:

    m_camera = new QCamera(this);
    m_videoProbe = new QVideoProbe(this);

    And now it works!

  • Qt Champions 2018

    hi @tomatoketchup,

    the first parameter of QVideoProbe constructor is the parent. if you set it, and the parent is destructed, your video probe object is also destructed and the memory freed. otherwise you are responsible for that.

    Edit: reference: http://doc.qt.io/qt-5/objecttrees.html


  • Thank you for the reply aha_1980!
    I just fixed the problem for real!
    The previous code created a memory leak, the QVideoProbe isn't deleted when I don't mention the parent.
    The reason for the warning was that I forgot to construct the QCamera with the parent parameter, it wasn't destroyed at all.
    I will edit my previous comment.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.