K_GLOBAL_STATIC and other macros

Sebastian TrĂ¼g strueg at mandriva.com
Fri Apr 13 10:45:00 BST 2007


While we are on it:
 What is the difference between
 Q_GLOBAL_STATIC and K_GLOBAL_STATIC?

Cheers,
Sebastian

On Friday 13 April 2007 11:27:43 Thiago Macieira wrote:
> Thomas Zander wrote:
> > I've been looking for a way to do statics since the kde3 method has been
> > deprecated. Unfortunately the only code example I found doesn't contain
> > enough information for me to figure how the macro applies to me (or even
> > how in general it works).
> >
> > Thats a generic problem with macros; they are not documented in our API
> > docs and in general you need a lot more then api docs anyway since their
> > usage tends to need more info than a generic method.  Its more in the
> > reach of class-docs in that there are quire some usages.
>
> Fortunately, in this case, the macro is very well documented in the
> apidocs: http://lxr.kde.org/source/KDE/kdelibs/kdecore/kernel/kglobal.h#071
>
> I have no idea where that shows up in api.kde.org or EBN. But the macro is
> documented nonetheless.
>
> > I'm looking for a way to;
> > init the static to zero initially;
> > Define a method like 'instance' or 'self' that either returns an existing
> > one or creates a new one including some initialisation code.
>
> K_GLOBAL_STATIC(MyType, name)
>
> Usage:
>    [...]
>    name->member = foo;
>    name->setFoo(foo);
>    MyType *ptr = name;
>    MyType &ref = *name;
>
> I.e., "name" behaves just like a pointer to MyType (MyType*).




More information about the kde-core-devel mailing list