Qt如何访问资源 [英] Qt how to access resources

查看:91
本文介绍了Qt如何访问资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Qt Creator可以将一些资源附加到项目中. 我在项目目录中创建了一个文件夹:Images.里面我有文件splash1.jpg

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

然后创建了Resources文件,并附加了该文件,如下图所示:

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" );

但是他们都不起作用.

如果我只放./Images/splash1.jpg至少可以用qmake手动编译,并且make可以工作,因为在运行时具有正确的路径,但无法使其在qt生成器中正常工作

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

有什么想法吗?

干杯

推荐答案

Qt5资源解释您所需要的一切.您必须将冒号放在源代码树中路径的前面.您还放置了前缀,所以:/Images/Images/splash1.jpg.

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.

这篇关于Qt如何访问资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆