How to solve the error message: "Could not create pixmap..."?
-
I have an old project named MotherVoice, which was written in Qt 5.14.0 several years ago. In preparation for upgrading to Qt 6, I downloaded Qt 5.15.2 and updated my scripts accordingly. The updated project worked properly except for one issue.
For clarity, please allow me to explain a bit about this project/app. In this app, sounds recorded from either the listener's mother or a female stranger will play. After hearing a sound, the listener decides whether it was their mother by pressing a button on the display. If the listener responds correctly, the app displays an image (named "correct.png") as visual feedback. Similarly, if the listener responds incorrectly, the app displays another image (named "incorrect.png").
Whenever the "correct.png" or "incorrect.png" images need to be shown, the app throws an error message: "Could not create pixmap from correct.png" at runtime. It seemed that this error was caused by my script for providing visual feedback.
To temporarily address this error, I changed the file path of the visual feedback image files (i.e., correct.png and incorrect.png) from
"background-image: url(../../../xResources/imageFiles/correct.png);"
to"background-image: url(correct.png);"
This worked only when I built a "release" version of the app and copied the correct.png and incorrect.png files into the same folder as MotherVoice.exe for deployment. However, this temporary fix does not resolve the problem when running the script directly from Qt Creator, either in debug mode or in release mode.I noticed that in the past, the "build" subfolder was outside of the project folder, but it is now a subfolder inside the project folder. I wonder if this might have something to do with the error message. My scripts for this project worked with older versions of Qt and Qt Creator, including displaying the correct.png and incorrect.png. These two images files remained the same. I did not change them at all. However, after upgrading to a new Qt version and using a new Qt Creator, I received an error message (as mentioned above).
For clarity, here is the entirety of the project file "MotherVoice.pro":
--- BEGINNING of MotherVoice.pro ---
QT += core gui widgets charts multimedia
TARGET = MotherVoice
TEMPLATE = appRC_ICONS = ../../../xResources/AEPLab_icon/AEP_logo_3D_original.ico
ICON = ../../../xResources/AEPLab_icon/AEP_logo_3D.icns
DEFINES += QT_DEPRECATED_WARNINGS
SOURCES +=
../../FuhClasses/CWav.cpp
../../FuhClasses/entryMotherVoice.cpp
main.cpp
subjectwindow.cpp
mainwindow.cpp
../../FuhClasses/FuhClasses.cpp
../../FuhClasses/dataMotherVoice.cpp
../../FuhClasses/recordMotherVoice.cpp \HEADERS +=
../../FuhClasses/CWav.h
../../FuhClasses/entryMotherVoice.h
subjectwindow.h
mainwindow.h
../../FuhClasses/FuhClasses.h
../../FuhClasses/dataMotherVoice.h
../../FuhClasses/recordMotherVoice.h
../../../xResources/FFTReal/v2.00/Array.h
../../../xResources/FFTReal/v2.00/Array.hpp
../../../xResources/FFTReal/v2.00/def.h
../../../xResources/FFTReal/v2.00/DynArray.h
../../../xResources/FFTReal/v2.00/DynArray.hpp
../../../xResources/FFTReal/v2.00/FFTReal.h
../../../xResources/FFTReal/v2.00/FFTReal.hpp
../../../xResources/FFTReal/v2.00/FFTRealFixLen.h
../../../xResources/FFTReal/v2.00/FFTRealFixLen.hpp
../../../xResources/FFTReal/v2.00/FFTRealFixLenParam.h
../../../xResources/FFTReal/v2.00/FFTRealPassDirect.h
../../../xResources/FFTReal/v2.00/FFTRealPassDirect.hpp
../../../xResources/FFTReal/v2.00/FFTRealPassInverse.h
../../../xResources/FFTReal/v2.00/FFTRealPassInverse.hpp
../../../xResources/FFTReal/v2.00/FFTRealSelect.h
../../../xResources/FFTReal/v2.00/FFTRealSelect.hpp
../../../xResources/FFTReal/v2.00/FFTRealUseTrigo.h
../../../xResources/FFTReal/v2.00/FFTRealUseTrigo.hpp
../../../xResources/FFTReal/v2.00/OscSinCos.h
../../../xResources/FFTReal/v2.00/OscSinCos.hppINCLUDEPATH +=
../../FuhClasses/
../../../xResources/FFTReal/v2.00/
../../../xResources/imageFiles/DISTFILES +=
../../../xResources/AEPLab_icon/AEP_logo_3D_original.ico
../../../xResources/imageFiles/correct.png
../../../xResources/imageFiles/incorrect.png--- END of MotherVoice.pro ---
Additionally, here is a snapshot of the structure of this project.
As you can see, both correct.png and incorrect.png are properly recognized as resources files for this project.In the scripts where visual feedback is provided, here is an section of code related to that:
--- BEGINNING of a small section of the script ---
// provide visual feedback when feedBackStatus is true. if (feedBackStatus) { if (wavFileName.contains(subCode.right(3))) // Assuming that the last 3 characters of the subCode is the subject number. { pushButtonChoice2->setStyleSheet( "QPushButton {" " background-image: url(../../../xResources/imageFiles/correct.png);" " background-repeat: no-repeat;" " background-position: center;" "}" "QPushButton:hover {" " background-color: rgb(0, 255, 255);" " border: 1px solid blue;" "}" ); } else { pushButtonChoice2->setStyleSheet( "QPushButton {" " background-image: url(../../../xResources/imageFiles/incorrect.png);" " background-repeat: no-repeat;" " background-position: center;" "}" "QPushButton:hover {" " background-color: rgb(0, 255, 255);" " border: 1px solid blue;" "}" ); } }
--- End of a small section of the script ---
I have tried using different paths in the .pro project and in the relevant section of scripts, but none worked. The only solution that worked was (as I mentioned above) to create a copy of correct.png and incorrect.png in the same folder as the compiled MotherVoice.exe. However, this does not seem to be a long-term solution.
I am very confused...
Any comments or suggestions will be greatly appreciated!
-
@SGaist That would be a fantastic solution: to include the two image files into the executable.
How to do that?
Any comments or suggestions will be appreciated!
@beginner123 said in How to solve the error message: "Could not create pixmap..."?:
How to do that?
See the documentation to the Qt resource system here: https://doc.qt.io/qt-6/resources.html
-
Hi,
This likely worked in a time where the project was built directly in source. This is something that is not done anymore.
If you want to avoid that kind of situation, the most simple is to use Qt's resource system where such file are built in the executable. -
Hi,
This likely worked in a time where the project was built directly in source. This is something that is not done anymore.
If you want to avoid that kind of situation, the most simple is to use Qt's resource system where such file are built in the executable.@SGaist That would be a fantastic solution: to include the two image files into the executable.
How to do that?
Any comments or suggestions will be appreciated!
-
@SGaist That would be a fantastic solution: to include the two image files into the executable.
How to do that?
Any comments or suggestions will be appreciated!
@beginner123 said in How to solve the error message: "Could not create pixmap..."?:
How to do that?
See the documentation to the Qt resource system here: https://doc.qt.io/qt-6/resources.html
-
I created a .qrc file and it worked! Thank you!
-