[Qt-interest] Is Qt smart anough not to load the same icon resource multiple times?
Andre Somers
andre at familiesomers.nl
Fri Feb 18 10:28:47 CET 2011
Op 17-2-2011 18:20, Girish Ramakrishnan schreef:
> Hi Daniel,
>
> On Thu, Feb 17, 2011 at 3:36 PM, Daniel Price<daniel.price at fxhome.com> wrote:
>> If I create multiple instances of a custom widget that loads an icon from a
>> resource like this:
>>
>>
>>
>> m_icon(QPixmap(“:/MyIcons/MyIcon.png”))
>>
>>
>>
>> is Qt smart enough to load the icon only once and implicitly share the
>> resource? Or it is loading the same icon multiple times and wasting memory?
>>
>>
> Yes. In addition to implicit sharing, QImage/QPixmap have a mechanism
> to share the data if they are from the same source. See
> QPixmap/QImage::cacheKey.
>
> This means that even with implicit sharing is not in use,
> QPixmap p1("foo.png");
> QPixmap p2("foo.png");
>
> will load foo.png only once. Both p1 and p2 have same cacheKey and
> will refer to the same data.
Turns out Qt is even more awesome than I thought it was! :-)
André
More information about the Qt-interest-old
mailing list