简体   繁体   English

QVideoProbe控件在仍被引用时销毁

[英]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. 我创建了一个QCamera和一个QVideoProbe,它们将允许我访问视频的每一帧。 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!!!'. 问题在于,每次我关闭该应用程序时,都会在Qt Creator中收到以下消息:“ QVideoProbe控件在仍被引用时被销毁了!!!”。

I'm using Qt 5.11 on Windows 8.1. 我在Windows 8.1上使用Qt 5.11。 My compilator is MSVC 2015 (32-bit). 我的编译器是MSVC 2015(32位)。

Here's my code: 这是我的代码:

Window::Window()
{
    if(!checkCameraAvailability())
    {
        QMessageBox::critical(this, "Error", "No camera is available");
        return;
    }

    m_camera = new QCamera;
    m_camera->setCaptureMode(QCamera::CaptureVideo);

    m_videoProbe = new QVideoProbe(this);

    if(!m_videoProbe->setSource(m_camera))
    {
        QMessageBox::critical(this, "Error", "setSource");
        return;
    }

    connect(m_videoProbe, SIGNAL(videoFrameProbed(QVideoFrame)), this, SLOT(cameraFrameProbed(QVideoFrame)));
    // For now the slot 'cameraFrameProbed' is empty

    m_camera->start();
}

What did I miss? 我错过了什么?

Problem solved! 问题解决了! I replaced this line: 我替换了这一行:

m_videoProbe = new QVideoProbe(this);

with this one: 与此:

m_videoProbe = new QVideoProbe;

But I still don't understand what was wrong with the first line. 但是我仍然不明白第一行出了什么问题。

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, there were actually 2 memory leaks... 我忘了在构造QCamera时提到它的父级,实际上有2个内存泄漏...

So the code becomes: 因此,代码变为:

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

And now it works! 现在就可以了!

Thank you so much Jeremy Friesner! 非常感谢Jeremy Friesner!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM