[Qt-interest] Is Qt smart anough not to load the same icon resource multiple times?

Srikanth srikanthsombhatla at gmail.com
Fri Feb 18 14:52:57 CET 2011


>
> Date: Thu, 17 Feb 2011 10:06:20 +0000
> From: Daniel Price <daniel.price at fxhome.com>
> Subject: [Qt-interest] Is Qt smart anough not to load the same icon
>        resource multiple times?
> To: "qt-interest at trolltech.com" <qt-interest at trolltech.com>
> Message-ID:
>        <902B548CE71AB640A08C9EDD266A8C883EB1FCCFBA at DELOREAN.fx.local>
> Content-Type: text/plain; charset="us-ascii"
>
> 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?
>
> I know that many Qt classes implicitly share their data when
> copy-constructed or assigned but how can members in separate instances
> 'know' about each other?
>
>

QPixmap is one of the classes that use implicit sharing, so that one pixmap
is shared unless one of the interested party modifies it. You can also have
a look at QPixmapCache to gain more control over pixmaps at application
level.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110218/149d963e/attachment.html 


More information about the Qt-interest-old mailing list