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. SIGSEGV QLabel->setPixmap(QPixmap::fromImage(.));

SIGSEGV QLabel->setPixmap(QPixmap::fromImage(.));

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 676 Views 1 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.
  • N Offline
    N Offline
    Netturbino85
    wrote on last edited by
    #1

    Good morning everyone,
    I hope someone can help me since other similar posts have not been helpful.
    I am currently working on an Linux embedded system that runs qt code and which reads the signals from two video inputs in parallel (dev0, dev1)
    and projects them to video using Qlabels.
    For some strange reason the code crashes when setPixmap is executed.
    I am using the v4l2 driver to read video signals in capture mode with mmap configuration.
    I tried to debug with gdb but I don't get valid information and the address provided, relative to SIGSEGV, is not valid or not present.
    Valgrind is not an option as it is not present in the embedded system.
    Thanks in advance for any suggestions. Here part of the code that manages the image.

    struct v4l2_buffer v4lbuf;
      CLEAR(v4lbuf);
    
      // Dequeue captured buffer
      v4lbuf.type   = V4L2_BUF_TYPE_VIDEO_CAPTURE;
      v4lbuf.memory = V4L2_MEMORY_MMAP;
      v4lbuf.index = bufferIdx%V4L2_BUFF_COUNT;
      ioctl(devVideo->handle(), VIDIOC_DQBUF, &v4lbuf);
    
      buffers->uyvy2rgb(bufferIdx%V4L2_BUFF_COUNT, true);
    
      const uchar* rgb = buffers->getRgbBuff();
      int bytesPerLine = buffers->getImageSize().width() * 3;
      int        width = buffers->getImageSize().width();
      int       height = buffers->getImageSize().height();
      QImage::Format format = QImage::Format_RGB888;
      if (rgb)
        image = QImage(rgb, width, height, bytesPerLine, format);
    
      // Queue captured buffer
      ioctl(devVideo->handle(), VIDIOC_QBUF, &v4lbuf);
    
      bufferIdx++;
      if(bufferIdx == V4L2_BUFF_COUNT)
        bufferIdx = 0;
    
      bufferImage = QImage(image.bits(), width, height, bytesPerLine, format);
      bufferImage.scaled(buffers->getImageSize().width(), buffers->getImageSize().height(), Qt::KeepAspectRatio);
      lbl->setPixmap(QPixmap::fromImage(bufferImage.copy()));
    

    The code does not crashe if lbl->setPixmap(QPixmap::fromImage(bufferImage.copy())); is commented.
    lbl is pass as QLabel* input

    Thanks in advance

    jsulmJ JonBJ N 3 Replies Last reply
    0
    • N Netturbino85

      Good morning everyone,
      I hope someone can help me since other similar posts have not been helpful.
      I am currently working on an Linux embedded system that runs qt code and which reads the signals from two video inputs in parallel (dev0, dev1)
      and projects them to video using Qlabels.
      For some strange reason the code crashes when setPixmap is executed.
      I am using the v4l2 driver to read video signals in capture mode with mmap configuration.
      I tried to debug with gdb but I don't get valid information and the address provided, relative to SIGSEGV, is not valid or not present.
      Valgrind is not an option as it is not present in the embedded system.
      Thanks in advance for any suggestions. Here part of the code that manages the image.

      struct v4l2_buffer v4lbuf;
        CLEAR(v4lbuf);
      
        // Dequeue captured buffer
        v4lbuf.type   = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        v4lbuf.memory = V4L2_MEMORY_MMAP;
        v4lbuf.index = bufferIdx%V4L2_BUFF_COUNT;
        ioctl(devVideo->handle(), VIDIOC_DQBUF, &v4lbuf);
      
        buffers->uyvy2rgb(bufferIdx%V4L2_BUFF_COUNT, true);
      
        const uchar* rgb = buffers->getRgbBuff();
        int bytesPerLine = buffers->getImageSize().width() * 3;
        int        width = buffers->getImageSize().width();
        int       height = buffers->getImageSize().height();
        QImage::Format format = QImage::Format_RGB888;
        if (rgb)
          image = QImage(rgb, width, height, bytesPerLine, format);
      
        // Queue captured buffer
        ioctl(devVideo->handle(), VIDIOC_QBUF, &v4lbuf);
      
        bufferIdx++;
        if(bufferIdx == V4L2_BUFF_COUNT)
          bufferIdx = 0;
      
        bufferImage = QImage(image.bits(), width, height, bytesPerLine, format);
        bufferImage.scaled(buffers->getImageSize().width(), buffers->getImageSize().height(), Qt::KeepAspectRatio);
        lbl->setPixmap(QPixmap::fromImage(bufferImage.copy()));
      

      The code does not crashe if lbl->setPixmap(QPixmap::fromImage(bufferImage.copy())); is commented.
      lbl is pass as QLabel* input

      Thanks in advance

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Netturbino85 said in SIGSEGV QLabel->setPixmap(QPixmap::fromImage(.));:

      lbl is pass as QLabel* input

      Is it also a valid pointer?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • N Netturbino85

        Good morning everyone,
        I hope someone can help me since other similar posts have not been helpful.
        I am currently working on an Linux embedded system that runs qt code and which reads the signals from two video inputs in parallel (dev0, dev1)
        and projects them to video using Qlabels.
        For some strange reason the code crashes when setPixmap is executed.
        I am using the v4l2 driver to read video signals in capture mode with mmap configuration.
        I tried to debug with gdb but I don't get valid information and the address provided, relative to SIGSEGV, is not valid or not present.
        Valgrind is not an option as it is not present in the embedded system.
        Thanks in advance for any suggestions. Here part of the code that manages the image.

        struct v4l2_buffer v4lbuf;
          CLEAR(v4lbuf);
        
          // Dequeue captured buffer
          v4lbuf.type   = V4L2_BUF_TYPE_VIDEO_CAPTURE;
          v4lbuf.memory = V4L2_MEMORY_MMAP;
          v4lbuf.index = bufferIdx%V4L2_BUFF_COUNT;
          ioctl(devVideo->handle(), VIDIOC_DQBUF, &v4lbuf);
        
          buffers->uyvy2rgb(bufferIdx%V4L2_BUFF_COUNT, true);
        
          const uchar* rgb = buffers->getRgbBuff();
          int bytesPerLine = buffers->getImageSize().width() * 3;
          int        width = buffers->getImageSize().width();
          int       height = buffers->getImageSize().height();
          QImage::Format format = QImage::Format_RGB888;
          if (rgb)
            image = QImage(rgb, width, height, bytesPerLine, format);
        
          // Queue captured buffer
          ioctl(devVideo->handle(), VIDIOC_QBUF, &v4lbuf);
        
          bufferIdx++;
          if(bufferIdx == V4L2_BUFF_COUNT)
            bufferIdx = 0;
        
          bufferImage = QImage(image.bits(), width, height, bytesPerLine, format);
          bufferImage.scaled(buffers->getImageSize().width(), buffers->getImageSize().height(), Qt::KeepAspectRatio);
          lbl->setPixmap(QPixmap::fromImage(bufferImage.copy()));
        

        The code does not crashe if lbl->setPixmap(QPixmap::fromImage(bufferImage.copy())); is commented.
        lbl is pass as QLabel* input

        Thanks in advance

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @Netturbino85
        As @jsulm says. If you want to know why lbl->setPixmap(QPixmap::fromImage(bufferImage.copy())); causes a SIGSEGV did you at least start by preceding that line with a Q_ASSERT(lbl)? That is not the whole story --- the pointer could be non-null but pointing to rubbish --- but it is at least one condition which you must check....

        1 Reply Last reply
        0
        • N Netturbino85

          Good morning everyone,
          I hope someone can help me since other similar posts have not been helpful.
          I am currently working on an Linux embedded system that runs qt code and which reads the signals from two video inputs in parallel (dev0, dev1)
          and projects them to video using Qlabels.
          For some strange reason the code crashes when setPixmap is executed.
          I am using the v4l2 driver to read video signals in capture mode with mmap configuration.
          I tried to debug with gdb but I don't get valid information and the address provided, relative to SIGSEGV, is not valid or not present.
          Valgrind is not an option as it is not present in the embedded system.
          Thanks in advance for any suggestions. Here part of the code that manages the image.

          struct v4l2_buffer v4lbuf;
            CLEAR(v4lbuf);
          
            // Dequeue captured buffer
            v4lbuf.type   = V4L2_BUF_TYPE_VIDEO_CAPTURE;
            v4lbuf.memory = V4L2_MEMORY_MMAP;
            v4lbuf.index = bufferIdx%V4L2_BUFF_COUNT;
            ioctl(devVideo->handle(), VIDIOC_DQBUF, &v4lbuf);
          
            buffers->uyvy2rgb(bufferIdx%V4L2_BUFF_COUNT, true);
          
            const uchar* rgb = buffers->getRgbBuff();
            int bytesPerLine = buffers->getImageSize().width() * 3;
            int        width = buffers->getImageSize().width();
            int       height = buffers->getImageSize().height();
            QImage::Format format = QImage::Format_RGB888;
            if (rgb)
              image = QImage(rgb, width, height, bytesPerLine, format);
          
            // Queue captured buffer
            ioctl(devVideo->handle(), VIDIOC_QBUF, &v4lbuf);
          
            bufferIdx++;
            if(bufferIdx == V4L2_BUFF_COUNT)
              bufferIdx = 0;
          
            bufferImage = QImage(image.bits(), width, height, bytesPerLine, format);
            bufferImage.scaled(buffers->getImageSize().width(), buffers->getImageSize().height(), Qt::KeepAspectRatio);
            lbl->setPixmap(QPixmap::fromImage(bufferImage.copy()));
          

          The code does not crashe if lbl->setPixmap(QPixmap::fromImage(bufferImage.copy())); is commented.
          lbl is pass as QLabel* input

          Thanks in advance

          N Offline
          N Offline
          Netturbino85
          wrote on last edited by
          #4

          Effectively, at the top of that function block I'm checking if the pointer is null but I will give a go using Q_ASSERT() instead. One question, could the problem be related to the image I pass as input? QImage use implicit data sharing and I wonder if can be corrupted, at memory level, in some way during thread process. Thanks for your suggestions.

          jsulmJ 1 Reply Last reply
          0
          • N Netturbino85

            Effectively, at the top of that function block I'm checking if the pointer is null but I will give a go using Q_ASSERT() instead. One question, could the problem be related to the image I pass as input? QImage use implicit data sharing and I wonder if can be corrupted, at memory level, in some way during thread process. Thanks for your suggestions.

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Netturbino85 said in SIGSEGV QLabel->setPixmap(QPixmap::fromImage(.));:

            during thread process

            This is something you should have said right at the beginning!
            Please run through debugger and post stack trace.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

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

              Hi,

              Based on what you wrote, it seems that all the image processing happens in a different thread and you access a GUI element from that thread. That is strictly forbidden. Use signals and slots to transfer your QImage back to the main thread to put it on your label.

              You can see a possible implementation of that in the Qt Mandelbrot example.

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

              N 1 Reply Last reply
              3
              • SGaistS SGaist

                Hi,

                Based on what you wrote, it seems that all the image processing happens in a different thread and you access a GUI element from that thread. That is strictly forbidden. Use signals and slots to transfer your QImage back to the main thread to put it on your label.

                You can see a possible implementation of that in the Qt Mandelbrot example.

                N Offline
                N Offline
                Netturbino85
                wrote on last edited by
                #7

                @SGaist I think that exactly my issue. I have implemented QMetaObject::invokeMethod() from worker threads but I can easily use signal and slot in case. I will check Monday and see if it solve the issue.

                Thanks for the suggestion.

                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