<QtResource> 代理页面

void Q_CLEANUP_RESOURCE(name)
void Q_INIT_RESOURCE(name)

宏文档

void Q_CLEANUP_RESOURCE(name)

卸载.qrc 文件指定的资源,该文件的基本名称为name

通常,Qt 资源会在应用程序终止时自动卸载,但如果资源位于一个正在卸载的插件中,请调用 Q_CLEANUP_RESOURCE() 强制移除资源。

注意: 此宏不能在命名空间中使用。有关解决方法,请参阅Q_INIT_RESOURCE 文档。

示例:

Q_CLEANUP_RESOURCE(myapp);

另请参阅 Q_INIT_RESOURCE() 和The Qt Resource System

void Q_INIT_RESOURCE(name)

使用指定的基本name 初始化.qrc 文件指定的资源。通常,当资源作为应用程序的一部分构建时,资源会在启动时自动加载。对于存储在静态库中的资源,Q_INIT_RESOURCE() 宏在某些平台上是必要的。

例如,如果应用程序的资源列在名为myapp.qrc 的文件中,您可以在main() 函数中添加此行,以确保在启动时初始化资源:

Q_INIT_RESOURCE(myapp);

如果文件名包含不能作为有效 C++ 函数名一部分的字符(如'-'),则必须用下划线字符('_')替换。

注意: 此宏不能在命名空间中使用。它应在 main() 中调用。如果无法调用,可采用以下变通方法,从函数MyNamespace::myFunction 启动资源myapp

inline void initMyResource() { Q_INIT_RESOURCE(myapp); }

namespace MyNamespace
{
    ...

    void myFunction()
    {
        initMyResource();
    }
}

另请参阅 Q_CLEANUP_RESOURCE() 和The Qt Resource System

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.