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
Forum Updated to NodeBB v4.3 + New Features

Qlable.setpixmap showing segmentation fault

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
4 Posts 2 Posters 712 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 last edited by swansorter
    #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()));
             
        }
    }
    
    JonBJ 1 Reply Last reply
    0
    • S swansorter

      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()));
               
          }
      }
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on 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
      1
      • JonBJ JonB

        @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 last edited by
        #3

        @JonB is there any alternative way.

        JonBJ 1 Reply Last reply
        0
        • S swansorter

          @JonB is there any alternative way.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on 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

          • Login

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