Important: Please read the Qt Code of Conduct -

Qt with openEXR and the code crashed

  • Hi everyone.
    I'm writing an image viewer.
    For EXR, I've compiled the source code to get:
    bin, includes, libs and dlls.
    The openEXR is compiled in x64 and the version is 3.
    zlib is x64
    Imath is x64
    My Qt is x64 and the free version.

    In the pro file, I added:
    LIBS += -l$$PWD/openEXR/lib/Iex-3_1_d
    LIBS += -l$$PWD/openEXR/lib/IlmThread-3_1_d
    LIBS += -l$$PWD/openEXR/lib/Imath-3_1_d
    LIBS += -l$$PWD/openEXR/lib/OpenEXR-3_1_d
    LIBS += -l$$PWD/openEXR/lib/OpenEXRUtil-3_1_d
    INCLUDEPATH += $$PWD/openEXR/include/Imath
    INCLUDEPATH += $$PWD/openEXR/include/openEXR

    My test code:

    #include <QWidget>
    #include <QtCore>
    #include <QtGui>
    #include <QImageIOPlugin>
    #include <half.h>
    #include <OpenEXRConfig.h>
    #include <ImfRgbaFile.h>
    #include <ImfRgba.h>
    #include <ImfArray.h>
    #include "namespaceAlias.h"
    class openEXRLoader:QObject
        explicit openEXRLoader();
        void writeRgba1 (const char fileName[],
                        const IMF::Rgba *pixels,
                        int width,
                        int height);
    #endif // OPENEXRLOADER_H


    #include "openexrloader.h"
        const char fileName[] = "D:/test.exr";
        //Declare a pointer in the memory for RGBA
        IMF::Rgba *pixels = NULL;
        int width = 100;
        int height = 100;
            writeRgba1(fileName, pixels, width, height);
        catch (const std::exception &exc)
            std::cerr << exc.what() << std::endl;
    void openEXRLoader::writeRgba1 (const char fileName[],
                const IMF::Rgba *pixels,
                int width,
                int height)
        IMF::RgbaOutputFile file (fileName, width, height, IMF::WRITE_RGBA);      // 1
        file.setFrameBuffer (pixels, 1, width);                         // 2
        file.writePixels (height);                                      // 3

    NO errors, but the code will crash.

    Which part do I did it incorrectly?

    Thank you for help.

  • @Sisqos said in Qt with openEXR and the code crashed:

    NO errors, but the code will crash.

    If code crashes, run under the debugger, and look at the stack trace when it crashes.

  • I found IMF::RgbaOutputFile is the reason to make a crash.
    We knew FreeImage can work with Qt directly, but openEXR can't.
    Does anyone know the reason?

  • I've solved the problem.
    I forget to consider that .exe require .dlls to execute.
    Just copy .dlls to the folder where .exe is executed.

Log in to reply