Error when Loading QImage
-
wrote on 28 Apr 2024, 20:21 last edited by
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.
-
wrote on 28 Apr 2024, 23:17 last edited by
When you mentioned you're using LLVM MinGW 64, is that the MinGW 11.2.0 64-bit compiler that can be installed via Qt's Maintenance app?
-
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?
-
wrote on 28 Apr 2024, 20:31 last edited by
@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:
-
@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.
-
What compiler do you use? How did you install Qt and please show your CMakeLists.txt.
wrote on 28 Apr 2024, 20:50 last edited by@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
-
wrote on 28 Apr 2024, 21:39 last edited by
If you try ,jpg or .gif files, do you still get the same warning, i.e " iCCP: known incorrect sRGB profile"?
-
If you try ,jpg or .gif files, do you still get the same warning, i.e " iCCP: known incorrect sRGB profile"?
wrote on 28 Apr 2024, 21:42 last edited by@hskoglund I only get that part of the error for pngs.
-
wrote on 28 Apr 2024, 21:56 last edited by
Just guessing, but if you disable your antivirus app, do you still get the same crash?
-
wrote on 28 Apr 2024, 22:52 last edited by
@hskoglund I turned off Windows real time virus protection and disabled all UAC. I also ran QT Creator as admin, but the error is still occuring.
-
wrote on 28 Apr 2024, 23:02 last edited by
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(); }
-
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(); }
wrote on 28 Apr 2024, 23:07 last edited by@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.
-
wrote on 28 Apr 2024, 23:17 last edited by
When you mentioned you're using LLVM MinGW 64, is that the MinGW 11.2.0 64-bit compiler that can be installed via Qt's Maintenance app?
-
When you mentioned you're using LLVM MinGW 64, is that the MinGW 11.2.0 64-bit compiler that can be installed via Qt's Maintenance app?
wrote on 28 Apr 2024, 23:31 last edited by bapcruz@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
-
-
2/13