No, you can't use any part of the cacheKey
to compare image content, it only exists to make sure an image hasn't changed since the last cacheKey
value was taken. It identifies the buffer and changes whenever any non-const function of the QImage
is called.
But as the name of the cacheKey
property implies, you can use it as a key for a QCache<qint64, QByteArray>
where you would store the actual hash of the image that you would only recalculate with QCryptographicHash
only if the image was changed (= only if it isn't already in the cache).
Also QImage
doesn't use a cache like QPixmap
for reading an image, so reading 3 times the same image file will allocate 3 distinct buffers, each time with a different cacheKey
. To avoid calculating the hashes each time, you should take a look at the source code of the QPixmap::load
function.