问题
Qt Creator give the possibility to attach some resource to the project. I created in the project directory a folder called: Images. inside i have the file splash1.jpg
I created then the Resources file and attached the file as shown in the following figure:

Which is now the correct way to access from code such a file? I tryed
QPixmap pixmap( "Images/splash1.jpg" );
QPixmap pixmap( "./Images/splash1.jpg" );
but none of them worked.
if i put just ./Images/splash1.jpg work at least if i compile by hand with qmake and make because has the correct path at runtime but no way to make it work within qt creator
Any idea??
Cheers,
回答1:
Qt5 resources explains all you need. You have to put the colon before the path in the source tree. You also have placed a prefix, so :/Images/Images/splash1.jpg
.
回答2:
The correct way to load with Qt resources is: :/Images/Images/splash1.jpg
.
What you could also do, is assign an alias to the resource. This way you don't need the .jpg: :/Images/splash
回答3:
You can use ":/prefix/name of your image".
来源:https://stackoverflow.com/questions/7741444/qt-how-to-access-resources