Q_INIT_RESOURCE

简介: Q_INIT_RESOURCE

https://doc.qt.io/qt-5/resources.html


Q_INIT_RESOURCE是Qt的资源机制(resource mechanism),它使程序在编译时将图片存储在.cpp文件中,运行时连接它。这要求你建立一个Qt资源文件***.qrc,在***.qrc中指定图片位置。编译时编译器将***.qrc中指定的图片以二进制数的形式存储到Qt自动建立的名为qrc_***.cpp的文件中,这里的***就是你建立***.qrc时的名字,而你在main()函数中使用Q_INIT_RESOURCE(name)宏时的name也必须是这个***。


Q_INIT_RESOURCE是Qt的资源机制。


使用方法:


Q_INIT_RESOURCE(name)

首先,我们自己需要建立一个XXX.qrc文件,“XXX”代表该资源的名字。上述代码中的name,就是代表需要初始化该资源。


具体的qrc文件内容的编写,可参考Qt官方文档The Qt Resource。


接下来,程序编译时,编译器根据传入的name,将XXX.qrc中指定的资源,以二进制数的形式存储到Qt自动建立的名为qrc_XXX.cpp的文件中,这里的XXX就是你建立.qrc文件的名字,也是调用Q_INIT_RESOURCE传入的name。


这句代码,写在类的构造函数中,可确保在静态链接的情况下将资源链接到最终的应用程序二进制文件中;写在main函数中,则全局可以使用。


同理,在将资源卸载的时候,需要调用Q_CLEANUP_RESOURCE()。


相关文章
Failed to load resource:9090/searchvideolist?mysearch%E8%B0%B7%E6%AD%8C:1
Failed to load resource:9090/searchvideolist?mysearch%E8%B0%B7%E6%AD%8C:1
|
1月前
|
Python
Cannot find reference ‘args‘ in ‘__init__.pyi‘ ,request要写对
Cannot find reference ‘args‘ in ‘__init__.pyi‘ ,request要写对
|
3月前
Cannot load keys from store: class path resource
Cannot load keys from store: class path resource
283 0
|
消息中间件 Java RocketMQ
【Java】Error creating bean with name ‘functionBindingRegistrar‘ defined in class path resource的一种解决方式
【Java】Error creating bean with name ‘functionBindingRegistrar‘ defined in class path resource的一种解决方式
104 0
|
NoSQL Java Redis
JedisConnectionException: Could not get a resource from the pool
JedisConnectionException: Could not get a resource from the pool
110 0
|
druid
A bean with that name has already been defined in class path resource and overriding is disabled.
A bean with that name has already been defined in class path resource and overriding is disabled.
192 0
|
NoSQL Redis
Could not get a resource from the pool
Could not get a resource from the pool
102 0
|
Android开发
Could not get resource ‘https://dl.google.com/dl/android/maven2/com/android/
Could not get resource ‘https://dl.google.com/dl/android/maven2/com/android/
354 0
|
存储 Android开发 索引
resource.arsc解析之 Dynamic package reference
加载Theme出错 这是一篇补充文章,在做动态替换resId的过程中,我发现bag类型的ResTable_entry在使用过程中存在问题。比如style,其parent解析一直有问题
263 0