[Patch] Fix undeleted "static QFont *_font" in kglobalsettings.cpp

Ingo Klöcker kloecker at kde.org
Thu Dec 4 19:42:11 GMT 2008


On Thursday 04 December 2008, Friedrich W. H. Kossebau wrote:
> Hi Louai,
>
> Am Donnerstag, 4. Dezember 2008, um 15:03 Uhr, schrieb Louai 
Al-Khanji:
> > On Thu, Dec 4, 2008 at 3:16 PM, Friedrich W. H. Kossebau
> >
> > <kossebau at kde.org> wrote:
> > > Two best practice questions, for handling the "QFont*
> > > mFonts[FontCount]"
> > >
> > > : 1. How to set an array of pointers all to 0 most efficiently
> > > : (mFonts)?
> >
> > Either memset or just loop through it.
>
> So no built-in mechanism? Alright.
>
> > > 2. How to mark the number of entries in an enum, so adding one
> > > more increases that number (FontCount) automatically?
> >
> > I don't know if there is a clean way to do it. If it is part of a
> > QObject you can use the meta object system to get the count.
> > Otherwise I tend to do something like this:
> >
> > enum Foo {
> >     Bar,
> >     Baz,
> >     FooSentinel /*  Keep as last entry, gives number of enum
> > elements */ }
>
> So is Bar always assigned to 0 by definition of C++?

Yes, but I think it's better pratice to add a FooBegin equaling the 
first enumerator value.


> And is there a nice KDE/Qt-pattern for naming the sentinel element?

Don't know. I suggest to call it FooEnd since this gives a nice 
correspondence to iterators, i.e.

enum Foo {
    Bar = FooBegin,
...
    FooEnd
}


Then a loop over all enumerator values would look as follows:

for ( int foo = FooBegin; foo < FooEnd; ++foo ) {
    // do something
}


Regards,
Ingo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20081204/55554ae5/attachment.sig>


More information about the kde-core-devel mailing list