Can Q_GLOBAL_STATIC replace KStaticDelete ?

Matthias Kretz kretz at
Mon Jan 22 20:46:54 GMT 2007

On Friday 19 January 2007 13:19, Thiago Macieira wrote:
> Matthias Kretz wrote:
> > Now it will abort with a helpful
> > error message if you access the global static after destruction (this
> > would have spared me one day of debugging if Q_GLOBAL_STATIC had
> > aborted instead of returning 0).
> > e.g.: accessed global static 'A *getA()' after destruction
> Good idea.

After trying it with some classes that were using KStaticDeleter before I 
think we must support the case where the global static is already deleted 
while some code might still access it if it's there.
Concrete example:
KSharedConfig keeps a global QList of all KSharedConfig objects. At some point 
this list will be deleted but there might still be KSharedConfig objects 
stored somewhere (new ones should not be created and should lead to an 
error). But in the dtor of KSharedConfig the object is taken out of the 
global list. Now a simple check is missing to make it not abort. See attached 
patch which adds another method "bool NAME##_isDestroyed()".

Matthias Kretz (Germany)                            <><
MatthiasKretz at, kretz at,
Matthias.Kretz at
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kglobal.h.diff
Type: text/x-diff
Size: 3045 bytes
Desc: not available
URL: <>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <>

More information about the kde-core-devel mailing list