Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QVideoProbe control destroyed while it's still being referenced

QVideoProbe control destroyed while it's still being referenced

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 776 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tomatoketchup
    wrote on last edited by
    #1

    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:

    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?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tomatoketchup
      wrote on last edited by tomatoketchup
      #4

      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!

      aha_1980A 1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

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

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tomatoketchup
          wrote on last edited by
          #3

          Hello SGaist,

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

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tomatoketchup
            wrote on last edited by tomatoketchup
            #4

            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!

            aha_1980A 1 Reply Last reply
            0
            • T tomatoketchup

              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!

              aha_1980A Offline
              aha_1980A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on last edited by aha_1980
              #5

              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

              regards

              Qt has to stay free or it will die.

              1 Reply Last reply
              2
              • T Offline
                T Offline
                tomatoketchup
                wrote on last edited by
                #6

                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.

                1 Reply Last reply
                2

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved