K_GLOBAL_STATIC and other macros

Thiago Macieira thiago at kde.org
Fri Apr 13 12:58:52 BST 2007


Thomas Zander wrote:
> On Friday 13 April 2007 12:37, Thomas Zander wrote:
>> Where can I call my init() method in the new style?
>
> Ok, it seems that what I need is not supported.

It is. You have to put the code in your object's constructor, though.

class MyStatic
{
public:
  MyStatic() { init(); }
  void init();
};
K_GLOBAL_STATIC(MyStatic, theStatic)

The destructor (if any) is called upon object destruction (see below).

> Thanks for the reference to the ebn docs.
>
> I wrote some more comments in the docs that would have helped me immensely
> for initial understanding; can someone comment on the correctness?

They are correct. In this part:
+ *     // A post routine is a way to delete the static instance when the
application quits.

I'd add that the installation of the post routine is not mandatory. The
object will be deleted anyways (as long as the platform isn't broken,
which can happen). The qAddPostRoutine is a way to make the object be
deleted inside ~QCoreApplication. Otherwise, it's deleted at program
unload.

-- 
  Thiago Macieira  -  thiago (AT) macieira.info - thiago (AT) kde.org
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358






More information about the kde-core-devel mailing list