Qt4 constructors
Kuba Ober
kuba at mareimbrium.org
Tue Sep 6 19:20:12 BST 2005
On Tuesday 06 September 2005 06:03, Guillaume Laurent wrote:
> Benjamin Meyer wrote:
> >I found http://doc.trolltech.com/4.0/qt4-intro.html, but doesn't go
> >into much detail, and simply says: "This makes subclassing easier, at
> >the same time as it helps make the Qt library more efficient."
> >
> >The vast majority of widgets don't need names which saves on memory,
> >startup time, and binary size.
>
> I agree in principle, but in practice widgets still need to be named in
> some cases, so they still need to have a const char* name member. The
> only improvement I can see is that a widget construction will be a wee
> bit faster because that member will directly be initialized to 0 rather
> than set to a '0' which comes from an argument in the higher level of
> the construction.
It wasn't as trivial. The name has to be copied, so that's how the member
initializer looked like in qt 3.3.3:
....
objname( name ? qstrdup(name) : 0 )
....
I presume that trolls have seen enough "client code" to determine that this
conditional was just a waste of CPU time. I have almost never used any names
in my own code, save for a few cases where I wrote designer-like code that
had to iterate on the widget tree and find some specific objects for which no
pointers were otherwise available.
The only thing that sets those names in real life, AFAIK, is uic-generated
code (in qt 3.x). Uic-generated code pervasively sets names (to equal the
class name), and that amounts to nothing more than heap waste unless you
actually have some use for those.
For a few embedded-style applications that I was working on some time ago I
simply modified uic not to emit the darn things.
Cheers, Kuba
More information about the kde-core-devel
mailing list