<?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <!-- qpixmapcache.cpp --> <head> <title>Qt 4.6: QPixmapCache Class Reference</title> <link href="classic.css" rel="stylesheet" type="text/css" /> </head> <body> <a name="//apple_ref/cpp/cl//QPixmapCache"></a> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td align="left" valign="top" width="32"><a href="http://qt.nokia.com/"><img src="images/qt-logo.png" align="left" border="0" /></a></td> <td width="1"> </td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="functions.html"><font color="#004faf">All Functions</font></a> · <a href="overviews.html"><font color="#004faf">Overviews</font></a></td></tr></table><h1 class="title">QPixmapCache Class Reference<br /><span class="small-subtitle">[<a href="qtgui.html">QtGui</a> module]</span> </h1> <p>The QPixmapCache class provides an application-wide cache for pixmaps. <a href="#details">More...</a></p> <pre> #include <QPixmapCache></pre><ul> <li><a href="qpixmapcache-members.html">List of all members, including inherited members</a></li> <li><a href="qpixmapcache-obsolete.html">Obsolete members</a></li> </ul> <hr /> <a name="public-types"></a> <h2>Public Types</h2> <table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%"> <tr><td class="memItemLeft" align="right" valign="top">class </td><td class="memItemRight" valign="bottom"><b><a href="qpixmapcache-key.html">Key</a></b></td></tr> </table> <hr /> <a name="static-public-members"></a> <h2>Static Public Members</h2> <table class="alignedsummary" border="0" cellpadding="0" cellspacing="0" width="100%"> <tr><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><b><a href="qpixmapcache.html#cacheLimit">cacheLimit</a></b> ()</td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qpixmapcache.html#clear">clear</a></b> ()</td></tr> <tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qpixmapcache.html#find">find</a></b> ( const QString & <i>key</i>, QPixmap * <i>pixmap</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qpixmapcache.html#find-3">find</a></b> ( const Key & <i>key</i>, QPixmap * <i>pixmap</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qpixmapcache.html#insert">insert</a></b> ( const QString & <i>key</i>, const QPixmap & <i>pixmap</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top">Key </td><td class="memItemRight" valign="bottom"><b><a href="qpixmapcache.html#insert-2">insert</a></b> ( const QPixmap & <i>pixmap</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qpixmapcache.html#remove">remove</a></b> ( const QString & <i>key</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qpixmapcache.html#remove-2">remove</a></b> ( const Key & <i>key</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><b><a href="qpixmapcache.html#replace">replace</a></b> ( const Key & <i>key</i>, const QPixmap & <i>pixmap</i> )</td></tr> <tr><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><b><a href="qpixmapcache.html#setCacheLimit">setCacheLimit</a></b> ( int <i>n</i> )</td></tr> </table> <a name="details"></a> <hr /> <h2>Detailed Description</h2> <p>The QPixmapCache class provides an application-wide cache for pixmaps.</p> <p>This class is a tool for optimized drawing with <a href="qpixmap.html">QPixmap</a>. You can use it to store temporary pixmaps that are expensive to generate without using more storage space than <a href="qpixmapcache.html#cacheLimit">cacheLimit</a>(). Use <a href="qpixmapcache.html#insert">insert</a>() to insert pixmaps, <a href="qpixmapcache.html#find">find</a>() to find them, and <a href="qpixmapcache.html#clear">clear</a>() to empty the cache.</p> <p>QPixmapCache contains no member data, only static functions to access the global pixmap cache. It creates an internal <a href="qcache.html">QCache</a> object for caching the pixmaps.</p> <p>The cache associates a pixmap with a user-provided string as a key, or with a <a href="qpixmapcache-key.html">QPixmapCache::Key</a> that the cache generates. Using <a href="qpixmapcache-key.html">QPixmapCache::Key</a> for keys is faster than using strings. The string API is very convenient for complex keys but the <a href="qpixmapcache-key.html">QPixmapCache::Key</a> API will be very efficient and convenient for a one-to-one object-to-pixmap mapping — in this case, you can store the keys as members of an object.</p> <p>If two pixmaps are inserted into the cache using equal keys then the last pixmap will replace the first pixmap in the cache. This follows the behavior of the <a href="qhash.html">QHash</a> and <a href="qcache.html">QCache</a> classes.</p> <p>The cache becomes full when the total size of all pixmaps in the cache exceeds <a href="qpixmapcache.html#cacheLimit">cacheLimit</a>(). The initial cache limit is 2048 KB (2 MB) on embedded platforms, 10240 KB (10 MB) on desktop platforms; you can change this by calling <a href="qpixmapcache.html#setCacheLimit">setCacheLimit</a>() with the required value. A pixmap takes roughly (<i>width</i> * <i>height</i> * <i>depth</i>)/8 bytes of memory.</p> <p>The <i>Qt Quarterly</i> article <a href="http://qt.nokia.com/doc/qq/qq12-qpixmapcache.html">Optimizing with QPixmapCache</a> explains how to use QPixmapCache to speed up applications by caching the results of painting.</p> <p>See also <a href="qcache.html">QCache</a> and <a href="qpixmap.html">QPixmap</a>.</p> <hr /> <h2>Member Function Documentation</h2> <a name="//apple_ref/cpp/clm/QPixmapCache/cacheLimit"></a> <h3 class="fn"><a name="cacheLimit"></a>int QPixmapCache::cacheLimit () <tt> [static]</tt></h3> <p>Returns the cache limit (in kilobytes).</p> <p>The default cache limit is 2048 KB on embedded platforms, 10240 KB on desktop platforms.</p> <p>See also <a href="qpixmapcache.html#setCacheLimit">setCacheLimit</a>().</p> <a name="//apple_ref/cpp/clm/QPixmapCache/clear"></a> <h3 class="fn"><a name="clear"></a>void QPixmapCache::clear () <tt> [static]</tt></h3> <p>Removes all pixmaps from the cache.</p> <a name="//apple_ref/cpp/clm/QPixmapCache/find"></a> <h3 class="fn"><a name="find"></a>bool QPixmapCache::find ( const <a href="qstring.html">QString</a> & <i>key</i>, <a href="qpixmap.html">QPixmap</a> * <i>pixmap</i> ) <tt> [static]</tt></h3> <p>Looks for a cached pixmap associated with the given <i>key</i> in the cache. If the pixmap is found, the function sets <i>pixmap</i> to that pixmap and returns true; otherwise it leaves <i>pixmap</i> alone and returns false.</p> <p>Example:</p> <pre> QPixmap pm; if (!QPixmapCache::find("my_big_image", &pm)) { pm.load("bigimage.png"); QPixmapCache::insert("my_big_image", pm); } painter->drawPixmap(0, 0, pm);</pre> <p>This function was introduced in Qt 4.6.</p> <h3 class="fn"><a name="find-3"></a>bool QPixmapCache::find ( const <a href="qpixmapcache-key.html">Key</a> & <i>key</i>, <a href="qpixmap.html">QPixmap</a> * <i>pixmap</i> ) <tt> [static]</tt></h3> <p>Looks for a cached pixmap associated with the given <i>key</i> in the cache. If the pixmap is found, the function sets <i>pixmap</i> to that pixmap and returns true; otherwise it leaves <i>pixmap</i> alone and returns false. If the pixmap is not found, it means that the <i>key</i> is no longer valid, so it will be released for the next insertion.</p> <p>This function was introduced in Qt 4.6.</p> <a name="//apple_ref/cpp/clm/QPixmapCache/insert"></a> <h3 class="fn"><a name="insert"></a>bool QPixmapCache::insert ( const <a href="qstring.html">QString</a> & <i>key</i>, const <a href="qpixmap.html">QPixmap</a> & <i>pixmap</i> ) <tt> [static]</tt></h3> <p>Inserts a copy of the pixmap <i>pixmap</i> associated with the <i>key</i> into the cache.</p> <p>All pixmaps inserted by the Qt library have a key starting with "$qt", so your own pixmap keys should never begin "$qt".</p> <p>When a pixmap is inserted and the cache is about to exceed its limit, it removes pixmaps until there is enough room for the pixmap to be inserted.</p> <p>The oldest pixmaps (least recently accessed in the cache) are deleted when more space is needed.</p> <p>The function returns true if the object was inserted into the cache; otherwise it returns false.</p> <p>See also <a href="qpixmapcache.html#setCacheLimit">setCacheLimit</a>().</p> <h3 class="fn"><a name="insert-2"></a><a href="qpixmapcache-key.html">Key</a> QPixmapCache::insert ( const <a href="qpixmap.html">QPixmap</a> & <i>pixmap</i> ) <tt> [static]</tt></h3> <p>Inserts a copy of the given <i>pixmap</i> into the cache and returns a key that can be used to retrieve it.</p> <p>When a pixmap is inserted and the cache is about to exceed its limit, it removes pixmaps until there is enough room for the pixmap to be inserted.</p> <p>The oldest pixmaps (least recently accessed in the cache) are deleted when more space is needed.</p> <p>This function was introduced in Qt 4.6.</p> <p>See also <a href="qpixmapcache.html#setCacheLimit">setCacheLimit</a>() and <a href="qpixmapcache.html#replace">replace</a>().</p> <a name="//apple_ref/cpp/clm/QPixmapCache/remove"></a> <h3 class="fn"><a name="remove"></a>void QPixmapCache::remove ( const <a href="qstring.html">QString</a> & <i>key</i> ) <tt> [static]</tt></h3> <p>Removes the pixmap associated with <i>key</i> from the cache.</p> <h3 class="fn"><a name="remove-2"></a>void QPixmapCache::remove ( const <a href="qpixmapcache-key.html">Key</a> & <i>key</i> ) <tt> [static]</tt></h3> <p>Removes the pixmap associated with <i>key</i> from the cache and releases the key for a future insertion.</p> <p>This function was introduced in Qt 4.6.</p> <a name="//apple_ref/cpp/clm/QPixmapCache/replace"></a> <h3 class="fn"><a name="replace"></a>bool QPixmapCache::replace ( const <a href="qpixmapcache-key.html">Key</a> & <i>key</i>, const <a href="qpixmap.html">QPixmap</a> & <i>pixmap</i> ) <tt> [static]</tt></h3> <p>Replaces the pixmap associated with the given <i>key</i> with the <i>pixmap</i> specified. Returns true if the <i>pixmap</i> has been correctly inserted into the cache; otherwise returns false.</p> <p>This function was introduced in Qt 4.6.</p> <p>See also <a href="qpixmapcache.html#setCacheLimit">setCacheLimit</a>() and <a href="qpixmapcache.html#insert">insert</a>().</p> <a name="//apple_ref/cpp/clm/QPixmapCache/setCacheLimit"></a> <h3 class="fn"><a name="setCacheLimit"></a>void QPixmapCache::setCacheLimit ( int <i>n</i> ) <tt> [static]</tt></h3> <p>Sets the cache limit to <i>n</i> kilobytes.</p> <p>The default setting is 2048 KB on embedded platforms, 10240 KB on desktop platforms.</p> <p>See also <a href="qpixmapcache.html#cacheLimit">cacheLimit</a>().</p> <p /><address><hr /><div align="center"> <table width="100%" cellspacing="0" border="0"><tr class="address"> <td width="40%" align="left">Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies)</td> <td width="20%" align="center"><a href="trademarks.html">Trademarks</a></td> <td width="40%" align="right"><div align="right">Qt 4.6.3</div></td> </tr></table></div></address></body> </html>