Error when Loading QImage
-
My program crashes when I try to load an image from my computer into a QImage. I made sure that the path to the file is correct and tried to make a QImage pointer, but it still results in an error. This was originally part of a larger program, but even in this simple recreation, it doesn't work.
Here is my code in main.cpp:
#include "mainwindow.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; QImage test; test.load("C:/IMAGES/IMAGE.png"); // crashes program w.show(); return a.exec(); }
Here is the error received when I used the debugger:
qt.gui.imageio: libpng warning: iCCP: known incorrect sRGB profile
HEAP[sdf.exe]:
Invalid address specified to RtlFreeHeap( 00000000000D0000, 0000000000DF7240 )There are also no changes in mainwindow.cpp and the header file, but I added "CONFIG += console" to the .pro file.
-
Can you load the png with a normal image viewer? Do other images work correct?
-
@Christian-Ehrlicher I can open the image with windows photo viewer, photoshop, MS paint, etc. Also I've gotten no other images to load and I've had the same error for all of them. I've tried making the image a jpg and gif as well, but they seem to have the same error. It's also only about 5-6KB so I don't see it taking up too much memory. Here's the image for reference:
-
What compiler do you use? How did you install Qt and please show your CMakeLists.txt.
-
@Christian-Ehrlicher I'm using LLVM MinGW 64 with Qt 6.7.1 in my Qt Creator kit. I installed Qt through the open source installer on the website (https://www.qt.io/download-qt-installer-oss?hsCtaTracking=99d9dd4f-5681-48d2-b096-470725510d34|074ddad0-fdef-4e53-8aa8-5e8a876d6ab4). I installed Qt 6.7.1 through the Qt Creator maintenance tool. I also made the project using QMake, so I don't think I have a CMakeLists.txt file. Here's the .pro file though:
QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += c++17 CONFIG += console # You can make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ main.cpp \ mainwindow.cpp HEADERS += \ mainwindow.h FORMS += \ mainwindow.ui # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target
-
Just to be sure it crashes in the test.load() statement, if you add a qDebug() directly after, you don't see any output from it in Qt Creator, like ...*QImage( ..." etc.? Say like this:
#include "mainwindow.h" #include <QApplication> #include "qdebug.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; QImage test; test.load("C:/IMAGES/IMAGE.png"); // crashes program qDebug() << test; w.show(); return a.exec(); }
-
@hskoglund I tried that and the program seems to just stop and crash when I load (without displaying anything in the console with the qDebug). I also tried to qDebug a basic message after the load, but it doesn't seem to print that either.
-
@hskoglund Yes. I also have MinGW installed separately on my computer so I could try quickly making another kit with those and see if it works.
Edit: Changing the version of MinGW in the kit worked! I tried using regular MinGW 64-bit and that made it work perfectly. Thanks so much
-
-