Does QQuickImageProvider use QPixmapCache ?
-
Afraid not, there is no public API for it. The limit is hardcoded here: https://qt.gitorious.org/qt/qtdeclarative/source/67a101af142355a0ca7cdc234b7ee1716a25d87c:src/quick/util/qquickpixmapcache.cpp#L89
Can I ask why you want to change it?
If you want to trim the cache, you can use QQuickWindow::releaseResources() and if you want to avoid textures being released, just keep a reference to the Image that uses them.
-
I have 7 QML image elements in a QML page and the image sources are change (every image has 5 different optional sources).
I saw that every source change calls the PixmapImageProvider::requestPixmap to load the image again and I want to reduce the number of times images will be reloaded again. -
IIRC, changing the source explicitly evicts the image element from the cache, so you want to avoid that as much as possible. What you want is to create one Image element for each of the sources and alternate between which one is visible: true.
For instance:
@
// ImageFlipper.qml
Item {
id: root
property int index: 0;
Image { source: "source1.png"; visible: root.index == 0 }
Image { source: "source2.png"; visible: root.index == 1 }
Image { source: "source3.png"; visible: root.index == 2 }
Image { source: "source4.png"; visible: root.index == 3 }
Image { source: "source5.png"; visible: root.index == 4 }
}
@ -
I saw on qquickpixmapcache.cpp that if the QQuickImageProvider image type is QQuickImageProvider::Pixmap, the createPixmapDataSync function convert the pixmap to QImage.
Is it better to use QQuickImageProvider::Image as the image type of the QQuickImageProvider ? -
The default implementation of QPixmap is based on QImage, so the conversion cost between the two is negligible.
QPixmap has some code making sure the format is somewhat more optimal though, such as keeping the image in ARGB32_Premultiplied and maybe discarding the alpha channel of pngs which in practice have no alpha, so you are probably better off using Pixmap.