Detailed DescriptionThe
QCache class is a template class that provides a cache.
QCachedefines a cache that stores objects of type T associated with keys oftype Key. For example, here’s the definition of a cache that storesobjects of type Employee associated with an integer key:
以下是
QCache的简单使用程序:
#include <qapplication.h>
#include <qwidget.h>
#include <qmultilineedit.h>
#include <qcache.h>
int main(int argc, char **argv)
{
QApplication a(argc, argv);
QWidget w;
w.resize(150,150);
a.setMainWidget(&w);
QMultiLineEdit edit(&w);
edit.setGeometry(10,10,130,130);
typedef QCache<char> StringCache;
StringCache stringcache;
stringcache.setMaxCost(6);
stringcache.insert("Sweden","Stockholm",2);
stringcache.insert("Germany","Berlin",2);
stringcache.insert("France","Paris",2);
stringcache.insert("England","London",2);
edit.insertLine(stringcache["England"]);
edit.insertLine(stringcache["France"]);
edit.insertLine(stringcache["Cermany"]);
edit.insertLine(stringcache["Sweden"]);
w.show();
a.exec();
}QCache 能用来创建具有大小受限的散列表。
stringcache.
setMaxCost(6) 为这个散列表设置了最大成本
stringcache.
insert(“Sweden”,”Stockholm”,2); 这表示每一个元素的成本为2。所以这样一共只能插入3个元素了。。。。。。当插入元素超过3个时,这个缓存会自动删除最长时间
没有被访问的元素,又因为所有的元素都未被访问,故删除第一个插入的元素。
<!--google_ad_client = "pub-0607928744763968";/* 468x15, 创建于 10-10-29 */google_ad_slot = "9027959185";google_ad_width = 468;google_ad_height = 15;//--> google_protectAndRun("ads_core.google_render_ad", google_handleError, google_render_ad);
标签: insert,
QCache,
Qt,
setMaxCost 本文链接: Qt 容器类 QCache使用 版权所有: Venus, 转载请注明来源Venus并保留链接地址!
相关文章