Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [SOLVED] Qt Raspi : Segmentation fault in paint function
Qt 6.11 is out! See what's new in the release blog

[SOLVED] Qt Raspi : Segmentation fault in paint function

Scheduled Pinned Locked Moved Mobile and Embedded
4 Posts 2 Posters 2.5k Views 2 Watching
  • 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.
  • A Offline
    A Offline
    Abin
    wrote on last edited by Abin
    #1

    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.

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

      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.

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

      A 1 Reply Last reply
      0
      • A Offline
        A Offline
        Abin
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • SGaistS SGaist

          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.

          A Offline
          A Offline
          Abin
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0

          • Login

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