[PATCH] KGlobal cleanup

Matthias Kretz kretz at kde.org
Mon May 21 15:16:38 BST 2007


On Monday 21 May 2007, David Faure wrote:
> On Monday 21 May 2007, Matthias Kretz wrote:
> > On Monday 21 May 2007, Matthias Kretz wrote:
> > >          inline KGlobalPrivate()
> > >
> > >              : stringDict(0),
> > >
> > >              locale(0),
> > > -            charsets(0),
> > > -            staticDeleters(new KStaticDeleterList)
> > > +            charsets(0)
> > >          {
> > > -            qAddPostRoutine(KGlobalPrivate::syncConfigs);
> > > +            // make sure all Qt global statics are created here, that
> > > way we may use them in the +            // dtor as well
> > > +            qrand();
> > > +            //qAddPostRoutine(KGlobalPrivate::syncConfigs);
> > >          }
> > >
> > >          inline ~KGlobalPrivate()
> > >          {
> > > +            //qRemovePostRoutine(KGlobalPrivate::syncConfigs);
> >
> > Ups, I actually didn't mean to send this, but now that it's out what do
> > you think of this hack instead of a Qt post routine? The idea is that,
> > since function local statics are destructed in the reverse order in which
> > they were constructed, a call to qrand() in KGlobalPrivate() will ensure
> > that the global static qrand() depends on is still available when
> > ~KGlobalPrivate is called.
>
> This would allow to use KConfig in global object destructors (because
> KConfig -> QTemporaryFile -> qrand)? Nice solution then.

The change above ensures that KConfig::sync() works until ~KGlobalPrivate() is 
done. So if you have KConfig objects in a custom global static you have to 
copy this hack to the ctor of your global static (or make sure that 
KGlobalPrivate gets constructed in your ctor). Calling qrand() in KConfig() 
could catch a few cases but still not all. So in general we should still 
discurage to use any Qt/KDE classes/functions in dtors of global statics...

-- 
________________________________________________________
Matthias Kretz (Germany)                            <><
http://Vir.homelinux.org/
MatthiasKretz at gmx.net, kretz at kde.org,
Matthias.Kretz at urz.uni-heidelberg.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20070521/616cb910/attachment.sig>


More information about the kde-core-devel mailing list