开发者

Qt how to access resources

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:

Qt how to access resources

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 ide开发者_如何学Ca??

Cheers,


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. This will give you a path. If you need a URL, then use the qrc: scheme.


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


You can use ":/prefix/name of your image".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜