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
|
4月前
|
Python
Cannot find reference ‘args‘ in ‘__init__.pyi‘ ,request要写对
Cannot find reference ‘args‘ in ‘__init__.pyi‘ ,request要写对
Field userMapper in zero.file.videoProject.service.UserService required a bean of type ‘zero.file.vi
Field userMapper in zero.file.videoProject.service.UserService required a bean of type ‘zero.file.vi
|
6月前
Cannot load keys from store: class path resource
Cannot load keys from store: class path resource
377 0
Error starting ApplicationContext. To display the auto-configuration report re-run your application
Error starting ApplicationContext. To display the auto-configuration report re-run your application
|
Java
ApplicationContext is unlikely to start due to a @ComponentScan of the default package
解决办法: 1、一般发出这个警告的原因是你把启动类直接放在的src目录下面。 2、你需要在src目录下面再建一个包,然后把启动类放到下面。 3、或者你错将启动类放到java文件中了,与项目包成了同级文件,你只需要将启动类放到项目包里就可以。
88 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的一种解决方式
142 0
|
NoSQL Java Redis
JedisConnectionException: Could not get a resource from the pool
JedisConnectionException: Could not get a resource from the pool
139 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.
219 0
|
NoSQL Redis
Could not get a resource from the pool
Could not get a resource from the pool
115 0