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. Qlable.setpixmap showing segmentation fault
QtWS25 Last Chance

Qlable.setpixmap showing segmentation fault

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
4 Posts 2 Posters 549 Views
  • 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.
  • S Offline
    S Offline
    swansorter
    wrote on 1 Jan 2022, 10:15 last edited by swansorter 1 Mar 2022, 05:10
    #1

    if i use a qlable inside qtcuncurrent function showing segmentation fault

    this is my code

    void MainWindow::image_plot()
    {
    
        while (1) {
            QImage img(RxBuffer, 2048, 1, QImage::Format_RGB888);
            ui->label->setPixmap(QPixmap::fromImage(img.rgbSwapped()));
             
        }
    }
    
    J 1 Reply Last reply 1 Jan 2022, 12:15
    0
    • S swansorter
      1 Jan 2022, 10:15

      if i use a qlable inside qtcuncurrent function showing segmentation fault

      this is my code

      void MainWindow::image_plot()
      {
      
          while (1) {
              QImage img(RxBuffer, 2048, 1, QImage::Format_RGB888);
              ui->label->setPixmap(QPixmap::fromImage(img.rgbSwapped()));
               
          }
      }
      
      J Offline
      J Offline
      JonB
      wrote on 1 Jan 2022, 12:15 last edited by
      #2

      @swansorter

      I assume your ui->port is a QLabel [sic.], though it makes life easier if you say so.

      • You must not directly access any UI element from any thread other than the main UI one. I guess you are using your method above in a QtConcurrently-run thread?

      • While you can use QImage in a non-UI thread, I believe you cannot use QPixmaps either.

      S 1 Reply Last reply 3 Jan 2022, 05:10
      1
      • J JonB
        1 Jan 2022, 12:15

        @swansorter

        I assume your ui->port is a QLabel [sic.], though it makes life easier if you say so.

        • You must not directly access any UI element from any thread other than the main UI one. I guess you are using your method above in a QtConcurrently-run thread?

        • While you can use QImage in a non-UI thread, I believe you cannot use QPixmaps either.

        S Offline
        S Offline
        swansorter
        wrote on 3 Jan 2022, 05:10 last edited by
        #3

        @JonB is there any alternative way.

        J 1 Reply Last reply 3 Jan 2022, 07:52
        0
        • S swansorter
          3 Jan 2022, 05:10

          @JonB is there any alternative way.

          J Offline
          J Offline
          JonB
          wrote on 3 Jan 2022, 07:52 last edited by
          #4

          @swansorter
          I don't know why you are using threads --- about half the time people use them they don't need to. But assuming you do, you can only communicate with the main UI thread by sending a signal, with whatever (non-UI-type) parameters are necessary which the UI thread has a slot on and acts upon receiving the signal.

          For example, since I believe secondary threads can use QImage but cannot use QPixmap (and certainly not call QLabel::setPixmap()) I think you could emit imageCaptured(img) from image_plot() and have a slot MainWindow::onImageCaptured(const QImage &img) which does the ui->label->setPixmap(QPixmap::fromImage(img.rgbSwapped())); in the main thread.

          1 Reply Last reply
          1

          4/4

          3 Jan 2022, 07:52

          • Login

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