Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    4
    7
    125
    Loading More Posts
    • 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
      Netturbino85 last edited by

      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

      jsulm JonB N 3 Replies Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @Netturbino85 last edited by

        @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 Reply Quote 1
        • JonB
          JonB @Netturbino85 last edited by

          @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 Reply Quote 0
          • N
            Netturbino85 @Netturbino85 last edited by

            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.

            jsulm 1 Reply Last reply Reply Quote 0
            • jsulm
              jsulm Lifetime Qt Champion @Netturbino85 last edited by

              @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 Reply Quote 1
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                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 Reply Quote 3
                • N
                  Netturbino85 @SGaist last edited by

                  @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 Reply Quote 0
                  • First post
                    Last post