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. QPixmap::fromImage(img) sometime crash.

QPixmap::fromImage(img) sometime crash.

Scheduled Pinned Locked Moved Unsolved General and Desktop
qpixmapqimage
6 Posts 5 Posters 5.0k 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.
  • M Offline
    M Offline
    mosleim
    wrote on last edited by
    #1

    this is my slot function. the slot is connected to signal from other thread. this function sometime work, sometime crash. when crash, "ui_start3" never printed. I think QPixmap::fromImage(img); is the problem. and try cath is not work.

    in spesific state, when i produce a new window, the program usally crash.

    how to check the img object is valid or try the code is safe to run?

    void MainWindow::updateUI(QImage img)
    {
        qDebug()<<"ui_start1";
    
        if (!img.isNull())
        {
            qDebug()<<"ui_start2"<<img.size();
            try {
                QPixmap p = QPixmap::fromImage(img);
                qDebug()<<"ui_start3";
                ui->lbl_image->setPixmap(p.scaled(ui->lbl_image->size(),
                                                   Qt::IgnoreAspectRatio, Qt::FastTransformation));
    
                qDebug()<<"ui_start4";
            } catch (...) {
            }
        }
        qDebug()<<"ui_start5";
    }
    
    YashpalY jsulmJ 2 Replies Last reply
    0
    • thamT Offline
      thamT Offline
      tham
      wrote on last edited by tham
      #2

      Is this work under single thread?Maybe it is a bug cause by multithread, like resource crash, or you manipulate pixmap/update gui in non gui thread.

      Besides, I think it would be better to print out the error messages(although it do not work in your case)

      catch(std::exception const &ex){
          qDebug()<<ex.what();
      }
      
      1 Reply Last reply
      0
      • M mosleim

        this is my slot function. the slot is connected to signal from other thread. this function sometime work, sometime crash. when crash, "ui_start3" never printed. I think QPixmap::fromImage(img); is the problem. and try cath is not work.

        in spesific state, when i produce a new window, the program usally crash.

        how to check the img object is valid or try the code is safe to run?

        void MainWindow::updateUI(QImage img)
        {
            qDebug()<<"ui_start1";
        
            if (!img.isNull())
            {
                qDebug()<<"ui_start2"<<img.size();
                try {
                    QPixmap p = QPixmap::fromImage(img);
                    qDebug()<<"ui_start3";
                    ui->lbl_image->setPixmap(p.scaled(ui->lbl_image->size(),
                                                       Qt::IgnoreAspectRatio, Qt::FastTransformation));
        
                    qDebug()<<"ui_start4";
                } catch (...) {
                }
            }
            qDebug()<<"ui_start5";
        }
        
        YashpalY Offline
        YashpalY Offline
        Yashpal
        wrote on last edited by
        #3

        @mosleim said in QPixmap::fromImage(img) sometime crash.:

        fromImage

        Try with new set of images in your application and ensure whether the problem is with images or something else.

        1 Reply Last reply
        0
        • M mosleim

          this is my slot function. the slot is connected to signal from other thread. this function sometime work, sometime crash. when crash, "ui_start3" never printed. I think QPixmap::fromImage(img); is the problem. and try cath is not work.

          in spesific state, when i produce a new window, the program usally crash.

          how to check the img object is valid or try the code is safe to run?

          void MainWindow::updateUI(QImage img)
          {
              qDebug()<<"ui_start1";
          
              if (!img.isNull())
              {
                  qDebug()<<"ui_start2"<<img.size();
                  try {
                      QPixmap p = QPixmap::fromImage(img);
                      qDebug()<<"ui_start3";
                      ui->lbl_image->setPixmap(p.scaled(ui->lbl_image->size(),
                                                         Qt::IgnoreAspectRatio, Qt::FastTransformation));
          
                      qDebug()<<"ui_start4";
                  } catch (...) {
                  }
              }
              qDebug()<<"ui_start5";
          }
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @mosleim What is the error message when your app crashes? sigsegv? Something else? Do you have stack trace? Did you try to debug your app? Is it always the same image causing the crash?

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

          M 1 Reply Last reply
          1
          • jsulmJ jsulm

            @mosleim What is the error message when your app crashes? sigsegv? Something else? Do you have stack trace? Did you try to debug your app? Is it always the same image causing the crash?

            M Offline
            M Offline
            mosleim
            wrote on last edited by mosleim
            #5

            @jsulm this is from "just in time debugger" of vs. in QtCreator not show an error. and Aplication is returned 0.

            Unhandled exception at 0x02001A00 (Qt5Guid.dll) in AutoLogMetalDetector.exe: 0xC0000005: Access violation reading location 0x228B6030
            
            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              Can you show how your create the image that you pass to the function ?

              Also, can you provide a stack trace of your application crash ?

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

              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