Search code examples
c++qtqresource

QResource: unregister .rcc files


We have an application with multiple themes, whom calls other minor apps. So, on main app there is something like that:

// User opens app with theme A
QResource::registerResource("theme_a.rcc");      // returns TRUE

// User changes theme to B
QResource::unregisterResource("theme_a.rcc");    // returns TRUE
QResource::registerResource("theme_b.rcc");      // returns TRUE

Everything works fine on main application. The problem begins when this software calls other qt apps.

Inside those minor apps we follow the same flow of register and unregister. The weird part is that register always works and unregister never works (only inside minors apps). It's happening something like that:

// User opens app with theme A
QResource::registerResource("minor_theme_a.rcc");      // returns TRUE

// User changes theme to B
QResource::unregisterResource("minor_theme_a.rcc");    // returns FALSE
QResource::registerResource("minor_theme_b.rcc");      // returns TRUE

Why is it happening? Is there a solution?


Solution

  • unregisterResource returns true if the resource is successfully unloaded and no references exist for the resource.

    So in your case there could be still some more references from some other forms.

    Important documentation with respect to unregisterResource:

    If there are QResources that currently reference resources related to the unregistered file, they will continue to be valid but the resource file itself will be removed from the resource roots, and thus no further QResource can be created pointing into this resource data. The resource itself will be unmapped from memory when the last QResource that points to it is destroyed.

    So my strong guess is some QResource is still pointing to the one that you tried to unregister.