[Qt-qml] Image Provider
Martin Jones
martin.jones at nokia.com
Thu Apr 1 00:42:39 CEST 2010
On Thursday 01 April 2010, ext Adriano Rezende wrote:
> Hi,
>
> > Images are already loaded in a separate thread, so I'm not sure I
> > understand the problem you're solving.
>
> Are you talking about setting asynchronous property to every image?
> This is not exactly what I want. I want to load all images once,
> regardless the objects that uses that images are loaded or not. So
> after the splash screen, no image loading would be necessary if the
> cache is big enough.
> And also I would like all core images to be ready when the object is
> presented, no async loading, to avoid the screen to behave like an
> html page being loaded.
QDeclarativeImageProver::request() is called by a secondary thread. Since, at
the moment, you can only use QPixmap in the main (GUI) thread, we must use
QImage.
QDeclarativeImageProver sounds close to the solution you're looking for, but
you are correct that the memory management is a problem if you want to keep
your QImages in memory permanently.
> > Ultimately the image has to be a QPixmap, and those can only be created
> > in the main (GUI) thread, so there is no way currently to avoid this
> > copy.
>
> Yes I know, my loader does the same thing that QDeclarativePixmapCache
> does. The transformation isn't the problem, I was talking about the
> memory issues in using the provider API. Since I would have to
> maintain a list of QImages that eventually would be converted
> (duplicated) to a QPixmap in the main thread.
>
> I don't feel uncomfortable with the current solution, I was just
> wondering if there is a better one. The downside is that I wouldn't be
> able to visualize it with the qml viewer.
I think perhaps the best solution for you currently would be to insert
QPixmaps directly into the cache. Unfortunately we have no API for doing
this, however...
Disclaimer: the suggestion below sneaks around private implementation, so
there are no guarantees that this will continue to work.
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);
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.
--
Martin.
More information about the Qt-qml
mailing list