QPixmap: Are resources automatically shared for the same path?
-
Hello,
I know that in the following code, not the entire image is copied, but Pix2 refers to the data of Pix1 with copy-on-write semantics:
QPixmap Pix1(":/some/path"); QPixmap Pix2 = Pix1;
What I am interested in is, does the same apply to the following:
QPixmap Pix1(":/some/path"); QPixmap Pix2(":/some/path"); // uses exact same path to resource file
Thank you in advance!
-
Hi
it does have
https://doc.qt.io/qt-5/qpixmap.html#cacheKey
which suggest Qt uses
https://doc.qt.io/qt-5/qpixmapcache.html#details
internally.
However, i never really tested if its loaded from cache or from res again.
But I dont know if fetching from cache would use the implicit sharing or return a
"full" QPixmap. -
@mrjj: better quote QPixmap::load():
Note that QPixmaps are automatically added to the QPixmapCache when loaded from a file in main thread; the key used is internal and cannot be acquired.
-
:)
And a note to self. Check the docs..
Thanks. -
Thank you for your helpful replies. I believe this answers my question.