[Qt-interest] analog of QPixmapCache for caching QImage

Andre Somers andre at familiesomers.nl
Mon Mar 8 08:41:26 CET 2010


Serge wrote:
> i need cacheLimit() - returns the cache limit (in kilobytes).
>
> Andre Somers wrote:
>   
>> Serge wrote:
>>     
>>> Hello,
>>>
>>> I need analog of QPixmapCache for caching QImage.
>>> Are there some ready implementations?
>>>   
>>>       
>> What functionality do you need, that QCache does not offer?
>>
>> André
>>     
A two minute browse through the qt docs tell me that is trivial to 
emulate with QCache.
QCache supports setting a maximum cost, and setting a cost for each 
inserted item. QImage has a byteCount method.
So, set QCache's maximum cost to the number of bytes you want to spend, 
and insert your QImages with the overloaded insert functions that takes 
a cost and feed in QImage::byteCount(). Done. Your QCache now behaves 
like QPixmapCache for all practical purposes.

If you want, you can make your own class that uses a QCache internally 
to match the API of QPixmapCache, that is trivial. Should be ready in no 
more than 10 minutes or so.

André




More information about the Qt-interest-old mailing list