QPixmap::fromImage(img) sometime crash.

  • 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)
        if (!img.isNull())
            try {
                QPixmap p = QPixmap::fromImage(img);
                                                   Qt::IgnoreAspectRatio, Qt::FastTransformation));
            } catch (...) {

  • 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){

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


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

  • Lifetime Qt Champion

    @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?

  • @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

  • Lifetime Qt Champion


    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 ?

Log in to reply