Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Cannot seem to load any images/bitmaps from QT Creators resource system
Hello, I am using
Qt Creator 4.6.0
Based on Qt 5.10.1 (MSVC 2015, 32 bit)
Built on Mar 27 2018 15:05:08
From revision 3ac2aa7bb5
On 64bit Windows7 Sp1 (Build 7601)
and I cannot seem to load any images/bitmaps from QT Creators resource system. Absolute filesystem paths work though.
ui->comboBox->addItem(QIcon("C:/Users/mammut/Documents/QT/QComboBoxDemo/png/xyz.png"),"Marius"); // <-- Works! ui->comboBox->addItem(QIcon(":/png/png/xyz.png"),"Zelda"); // <-- Does not work! ui->comboBox->addItem(QIcon("qrc:/png/png/xyz.png"),"Hank"); // <-- Does not work! It's all the same file and the problem is also present in QT Creators 'Action Editor' for the main menu or when I use QPixmap() and setPixmap() to load a resource. Icons/images won't show up when the application is run.
Hi and welcome to devnet,
Qt Creator is an IDE and has nothing to do with Qt's resource system except helping you edit the corresponding files.
Can you show the content of the .qrc file that you are using for your application ?
Those are the contents of the .qrc file:
Do you have the same problem if you use an alias like described here ?
Both statements don't work.
ui->comboBox->addItem(QIcon(":/png/foo"),"Zelda"); // <-- doesn't work!
ui->comboBox->addItem(QIcon("qrc:/png/foo"),"Hank"); // <-- doesn't work!
What if you use
ui->comboBox->addItem(QIcon("qrc:///png/foo"),"Hank"); // Doesn't work...
ui->comboBox->addItem(QIcon("qrc:///png/png/xyz.png"),"Hank"); // Doesn't work neither...
Well, the first time I installed QT+QT Creator I deselected mingw53_32.
Now I created a parallel installation of QT+QT Creator of the same revison ( 3ac2aa7bb5) and this time I also installed the mingw53_32 option in addition
to the MSVC2017_64bit option.
Now alias versions work:
ui->comboBox->addItem(QIcon(":/png/foo"),"Hank"); // <-- works!
The number of slashes following the colon don't seem to matter though.
But non-alias versions or url versions ( qrc:/ ) still don't work.
Also as before the .exe runs from the 'Desktop_Qt_5_10_1_MSVC2017_64bit-Debug' directory, so I suspect the IDE is still using the same compiler.
You can use right click menu to get path to the files so you are 100% sure its correct.
Also, after you have added the file to the qres file and compiled.
If you then go check in a from with QLabel's pixmap, can it then show your images ?
Thanks, yes, I know, I had been doing that all along, but It would't work no matter what.
The only thing, that worked was reinstalling with most notably mingw53_32 selected in addition. Now at least the path version of the alias works, but nothing else.
It must have something todo with the options you select when installing Qt+Qt Creator. Also maybe besides from mingw53_32 I selected another additional option during reinstallation,
but that's all I changed on my configuration in order to get it to work.
And yes the images/bitmaps show up fine inside the Qt creators designer, although
sometimes you have to save your project with 'save all' before they do.
But when the application was run after compilation, they didn't show up in the app.
Just to be clear.
It shows the icons when you browse them but when you run INSIDE creator its
not showing the images that should be compiled into the exe?
Or is it only if you go double click the exe in the build folder?
There is nothing you can de-select during install that disables ressources.
Its a core feature.
Could you try this test project ?
" It shows the icons when you browse them but when you run INSIDE creator its
not showing the images that should be compiled into the exe?"
Ok, and test project also does this ?
Check if "Compiler output" contains
C:\Qt\5.10.0\msvc2015_64\bin\rcc.exe -name icons ..\untitled56\icons.qrc -o debug\qrc_icons.cpp
( or similar if using mingw. path will be different to rcc.exe)
Sounds like they are not compiled in for some reason.
The "Burning Sun's Avatar" thing is showing when running the application after
setting the project up with the msvc kit option.
'D:\QT_2nd\5.10.1\msvc2017_64\bin\rcc.exe -name icons ..\untitled56\icons.qrc -o debug\qrc_icons.cpp' <-- This does indeed show up in compiler output so the test project seems to work just fine.
Ok so your kit seems valid and rcc is run.
Try to delete complete build folder for your project and
run rebuild all and check if your project calls rcc.exe
rcc is called and the .png shows up :
D:\QT_2nd\5.10.1\msvc2017_64\bin\rcc.exe -name resource ..\QComboBoxDemo\resource.qrc -o debug\qrc_resource.cpp
but this is still the only synthax that works:
Also before reinstalling no synthax variant at all worked, that's for shure.
But now image loading is feasable of course, so the problem is not that urgent anymore. Still it's strange why other synthax variants don't work as supposed, and why things only started to come together after reinstalling Qt+Qt Creator. Anyways...
That is a bit odd. But I have only used ":/" with icons and
"qrc:/" with QML so would not have noticed if was broken once.
Regarding the reinstall- maybe scanner ate rcc.exe the first time or something else
blocked from being installed. Hard to guess at. its normally always included.
You mean anti-malware scanner? Well that would have to be windows defender then, since I don't have anything else installed of that nature.
Is there maybe still a way to somehow exclude rcc from installation by making wrong selections in the dialogs during installation of Qt+Qt Creator? You said it's a core feature, but...
Yeah, but its rare i have seen Defender eat anything so most likely something else.
As far as I know, rcc i included in all precompiled and there is no option to not have it installed.
Hm, removed the mingw53_32 folder from the installation because I thought that
maybe "QT Creator" itself somehow needed mingw53_32 to be present to function correctly, but nothing changed. The path to the alias still works correctly although
other synthaxes don't work, but that seems to be another issue so maybe my build directory just got corrupted somehow. Anyhow thanks for your help.
The non-alias resource path works too now. Cool ;-)
You can't seem to use a non-alias resource path once an alias has been assigned.
and then you cannot use ":/images/cut-img.png" anymore ?
Exactly. Once an alias has been defined, I can access the resource by that alias exclusively.
Ok, not sure if by design or not working.
Seems to be the same for Desktop_Qt_5_10_1_MinGW_32bit-Debug.
Before I was using Desktop_Qt_5_10_1_MSVC2017_64bit-Debug.
I thinks by design. Its not ALSO listed under org name so
only the alias name is available.
O.K. I see.
Seems like it helps to delete the build folder or clean project and run qmake+rebuild.