[Interest] setting a widget style for a particular widget class only?

René J. V. Bertin rjvbertin at gmail.com
Mon Sep 12 10:53:40 CEST 2016


Andy wrote:

Hi,

> My comment was actually about the call to QStyleFactory::create().  I
> wasn't sure if QStyleFactory created it and kept track of it somewhere
> (only load a style once?) or if I needed to manage it myself.  Usually when
> I write these kinds of methods (static methods on classes which create
> things) I like to document who owns the resulting pointer so there's no
> question who's going to manage the memory.


Indeed. It's not clear if QStyleFactory::create() returns a reference to the 
same internal object and thus if it should (or not) be called for each widget 
instance. The fact that there is no public dtor also doesn't help in determining 
if and when the pointer should be deleted.

I have a hunch that styles are loaded/initialised only once, so we get a 
reference to some internal object, and at most deleting the QStyle pointer will 
release the reference (or decrease a refcount) without trying to unload the 
style. But it's nice to know such things. Even if it's just a (strong) advice 
never to try to delete/unload this kind of resource as no one can tell when 
during an application exit it is going to be used.

R.




More information about the Interest mailing list