[SOLVED] Qt Raspi : Segmentation fault in paint function



  • Hi,

    I try to show an image received from a camera. When i try to paint it gives me segmentation fault.

    SD_Camera::SD_Camera(QQuickItem *parent) :
        QQuickPaintedItem(parent)
    {
        qDebug() << Q_FUNC_INFO << "Invoked";
    
        if ( startCamera())
        {
            qDebug() << Q_FUNC_INFO << "start timer";
            m_timer.start(20);
        }
    
        connect(&m_timer, SIGNAL(timeout()), this, SLOT(updateScreen()));
    }
    
    void SD_Camera::paint(QPainter *painter)
    {
        // SEGMENTATION FAULT OCCURS HERE****
        painter->drawImage(QRect(50,50,50,50), m_image);
    }
    ...
    
    void SD_Camera::updateScreen()
    {
        qDebug() << Q_FUNC_INFO << "Invoked";
        cv::Mat matImage;
    ...
            m_image = cvMatToQImage( matImage );
            update();
    }
    
    QImage SD_Camera::cvMatToQImage(cv::Mat matImage_i )
    {
        // *** IF AN IMAGE LOADED FROM SYSTEM IS RETURNED NO ERROR OCCURS
        cv::cvtColor( matImage_i, matImage_i, cv::COLOR_RGB2BGR );
        QImage image( (uchar*)matImage_i.data, matImage_i.cols, matImage_i.rows,
                      matImage_i.step, QImage::Format_RGB888);
    
        return image;
    }
    

    Is there any issue occurring while mat image is converted to QImage? if i check isNull() for the QImage is says it is not null.


  • Lifetime Qt Champion

    Hi,

    When using that constructor, that data are not copied (it's all explained in the doc of the constructor) and you must ensure that it's available until you're not using the QImage any longer.



  • This post is deleted!


  • @SGaist Thanks ...
    The case you mentioned was my problem. It is solved by using copy() of QImage. :)


Log in to reply
 

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