#include <QApplication>#include <QPixmapCache>#include "zzz.h"int main(int argc, char *argv[]){ QApplication app(argc, argv); QPixmapCache::setCacheLimit(20*1024); QTimer *t = new QTimer; t->start(10); ZZZ *a = new ZZZ; QObject::connect(t,SIGNAL(timeout()),a,SLOT(timer())); return app.exec();}
#ifndef ZZZ_H#define ZZZ_H#include <QtGui>class ZZZ: public QObject{ Q_OBJECTpublic: ZZZ();public slots: void timer() { QPixmap *pm = QPixmapCache::find("1"); if(!pm) { QPixmapCache::insert("1",QPixmap("1.jpg")); qDebug()<<QTime::currentTime()<<QPixmapCache::find("1")->size(); } }};#endif // ZZZ_H
#include "zzz.h"ZZZ::ZZZ(){}
C++ (Qt)bool find ( const QString & key, QPixmap * pixmap )bool find ( const Key & key, QPixmap * pixmap )
void timer() {// qDebug()<<QTime::currentTime()<<"zzz"; QPixmap pm; if(!QPixmapCache::find("1",&pm)) { QPixmapCache::insert("1",QPixmap("1.jpg")); QPixmapCache::find("1",&pm); qDebug()<<QTime::currentTime()<<pm.size(); }
QPixmapCache::setCacheLimit(20*1024);
QTime("12:29:10") zzz QTime("12:29:10") QSize(2000, 1000) QTime("12:29:10") zzz QTime("12:29:10") zzz QTime("12:29:11") zzz QTime("12:29:11") zzz