Qt how to access resources

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-18 14:14:15

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!