Unhandled exception while setScene (using QGraphicsScene and QGraphicsView)



  • Hi,
    I try to get view from camera and do two things:

    1. display that viewin GUI
    2. get QImage from view and process it

    Little earlier on forum I ask a question about getting QImage from camera view. I looked for a solution for my own and I found that I can write a class that inherits by QAbstractVideoSurface and implements methods: supportedPixelFormats and present from that class.
    I did this like was in example I found, but it only assumed getting QImage from a view to process it(so it is only one of my points).

    bool CameraFrameGrabber::present(const QVideoFrame &frame)
    {
        if (frame.isValid()) 
        {
            QVideoFrame cloneFrame(frame);
            cloneFrame.map(QAbstractVideoBuffer::ReadOnly);
            QImage image(cloneFrame.bits(),
                         cloneFrame.width(),
                         cloneFrame.height(), 
                         QVideoFrame::imageFormatFromPixelFormat(cloneFrame.pixelFormat()));
            QImage copyImg = image.copy();
    
            if(m_view!=NULL && m_scene !=NULL)  // that 'if' is my idea
            {
              m_scene->addPixmap(QPixmap::fromImage(image));
              m_scene->setSceneRect(image.rect());
              //m_view->setScene(m_scene);  // When it is commented there is no unhandled exception shown
            }
        
           emit frameAvailable(copyImg);
           cloneFrame.unmap();
           return true;
        }
    return false;
    }
    

    If that line with setScene is uncommented I get unhandled exception:
    "Unhandled exception at 0x539bc9c7 (msvcr100d.dll) in cameraTest.exe: 0xC0000005: Access violation reading location 0x0d2a0050."
    and programm stops in mamcpy.asm file at line:
    "rep movsd ;N - move all of our dwords"

    Maybe I'm doing sth wrong. Maybe something that I do is not allowed. But I don't know what I'm doing wrong.

    m_scene -> it is QGraphicsScene I create in constructor of CameraFrameGrabber
    m_view -> it is QGraphicsView that I create in ui file

    CameraFrameGrabber::CameraFrameGrabber(QObject *parent, QGraphicsView* view)
      : QAbstractVideoSurface(parent)
    {
      m_view = view;
      m_scene = new QGraphicsScene();
    }


  • m_view->setScene(m_scene); 
    

    is only needed once. Put it in your constructor after initialization of QGraphicsScene.

    If your Program crashes anyway after that change then your QGraphicsView that is passed in the constructor must be NULL !
    Make sure it is created correctly.
    Have you debugged and checked if your GraphicsView is correctly initialized ?


Log in to reply
 

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