QResource:注销.rcc文件 [英] QResource: unregister .rcc files

查看:77
本文介绍了QResource:注销.rcc文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个具有多个主题的应用程序,这些应用程序称为其他次要应用程序.因此,在主应用程序上有类似这样的内容:

 //用户打开主题为A的应用QResource :: registerResource("theme_a.rcc");//返回TRUE//用户将主题更改为BQResource :: unregisterResource("theme_a.rcc");//返回TRUEQResource :: registerResource("theme_b.rcc");//返回TRUE 

在主应用程序上一切正常.当此软件调用其他qt应用程序时,问题开始.

在这些次要应用程序中,我们遵循相同的注册和注销流程.奇怪的是,注册始终有效,而取消注册则永远无效(仅在未成年人应用程序内部).发生了这样的事情:

 //用户打开主题为A的应用QResource :: registerResource("minor_theme_a.rcc");//返回TRUE//用户将主题更改为BQResource :: unregisterResource("minor_theme_a.rcc");//返回FALSEQResource :: registerResource("minor_theme_b.rcc");//返回TRUE 

为什么会这样?有解决办法吗?

解决方案

unregisterResource 如果成功卸载资源并且没有针对该资源的引用,则返回true.

因此,在您的情况下,可能还会有其他形式的引用.

有关 unregisterResource 的重要文档:

如果存在当前引用与未注册文件相关的资源的QResource,它们将继续有效,但是资源文件本身将从资源根目录中删除,因此无法再创建QResource指向此资源数据.当最后一个指向资源的QResource被销毁时,资源本身将不会从内存中映射.

因此,我的强烈猜测是,某些 QResource 仍指向您尝试注销的那个.

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?

解决方案

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.

这篇关于QResource:注销.rcc文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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