清除QML图像缓存 [英] Clear QML image cache

查看:339
本文介绍了清除QML图像缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有3个QML图像元素的QML Flickable,可循环浏览8个图像文件.我的问题是,这在Symbian设备上仅占用很少的内存.因此,当有人将应用程序最小化时,其他应用程序将没有太多内存.我想知道可以对失去焦点的事件使用什么功能来释放缓存.否则,当手机内存不足时,Symbian会关闭我的应用程序.

I have a QML Flickable with 3 QML image elements that cycle through 8 image files. My problem is that this uses a lot of memory on a Symbian device with very little. So when someone minimizes the app there isn't a lot of memory left for other apps. I want to know what function I can use on the focus lost event to release the cache. Otherwise Symbian closes my app when the phone runs out of memory.

推荐答案

我只是遇到了一个非常相似的情况(从字面上看).显然,QML缓存是硬编码在Qt源内部的.我在 http://lists.qt找到了相关的帖子.nokia.com/pipermail/qt-qml/2011-June/002743.html .

I just ran into a very similar situation (literally). Apparently the QML cache is hardcoded deep inside the Qt source. I found a relevant posting at http://lists.qt.nokia.com/pipermail/qt-qml/2011-June/002743.html.

不幸的是,从该链接派生的解决方案需要修改您的Qt版本.我不知道这是否适合您的情况.

Unfortunately, a solution deriving from that link requires modifying your Qt build. I don't know if that's appropriate for your situation.

我目前的想法是,在 src/declarative/util/qdeclarativepixmapcache.cpp 文件顶部定义的四个常量(从上面的链接引用的第66-69行)控制何时以及为什么QML图像缓存已修改.我将CACHE_EXPIRE_TIME常量设置为0,因为该文件中的进一步逻辑表明,将该常量设置为0时,缓存中的项目会立即过期,因此将被删除.随着事情的发展,我将更新这个答案.

My current thinking is that the four constants defined at the top of src/declarative/util/qdeclarativepixmapcache.cpp file (lines 66-69, referenced from the above link) control when and why the QML image cache is modified. I'm setting the CACHE_EXPIRE_TIME constant to 0, as further logic inside that file indicates that with the constant set to 0, items in the cache expire immediately, and will therefore be removed. I'll update this answer as things develop.

我提出的解决方案确实奏效了.在QDeclarativePixmapCache.cpp文件中,将第68行更改为

My proposed solution did work. In the QDeclarativePixmapCache.cpp file, change line 68 from

#define CACHE_EXPIRE_TIME 30

#define CACHE_EXPIRE_TIME 0

重建Qt和您的应用程序,图像将不会被缓存(或者至少,我看到的行为表明不再缓存图像).此解决方案有两个缺点:

Rebuild Qt and your application, and images will not be cached (or at least, the behavior I'm seeing would indicate that images are no longer being cached). There are a couple of downsides to this solution:

  1. 需要修改Qt源树
  2. 未知的性能影响了整个应用程序-对我来说不是问题,而是要考虑的问题.

此解决方案适用于Qt 4.7版.祝你好运!

This solution worked with Qt version 4.7. Good luck!

这篇关于清除QML图像缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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