[Qt-qml] Image Provider

Adriano Rezende adriano.rezende at openbossa.org
Thu Apr 1 02:07:51 CEST 2010


Hi,

> QDeclarativePixmapCache is based on QPixmapCache, so with the correct key, you
> can poke something into the cache that QML can pull out:

> QByteArray key = url.toEncoded(QUrl::FormattingOption(0x100));
> QPixmapCache::insert(QString::fromLatin1(key.constData(), key.count()),
pixmap);

Yes, I was thinking about injecting into the cache with this same key,
but I thought this would be an invasive solution.

One thing that comes to my mind is that the QPixmap::load() uses a
different key format to insert into the cache. The follow one:

QString key = QLatin1String("qt_pixmap_") + info.absoluteFilePath() +
QLatin1Char('_') + QString::number(info.lastModified().toTime_t()) +
QLatin1Char('_') +
        QString::number(info.size()) + QLatin1Char('_') +
QString::number(data ? data->pixelType() : QPixmapData::PixmapType);

And Qml uses that one you showed. This wouldn't result in duplicated
images into the cache?
For example, if I load an image using QPixmap::load() and the same
image using an Image.source property from Qml.

> Perhaps in the future we could add a
> QDeclarativePixmapCache::insert(QUrl,QPixmap) method, which would still be
> private, but at least it would change with the rest of
> QDeclarativePixmapCache.

I think it would be nice a method in QPixmapCache that returns a key
given a QFileInfo. Like the follow one:

static QPixmapCache::Key QPixmapCache::keyFromFileInfo(const QFileInfo &info);

This method could be used for QPixmap, for Qml (at least for local
files) and by developers who would like to search or add in the cache
given a file path, maintaining consistency. What do you think?


Cheers,
Adriano



More information about the Qt-qml mailing list