Can Q_GLOBAL_STATIC replace KStaticDelete ?

Matthias Kretz kretz at kde.org
Wed Jan 17 18:20:53 GMT 2007


On Wednesday 17 January 2007 16:38, Olivier Goffart wrote:
> Le mercredi 17 janvier 2007 15:43, Matthias Kretz a écrit :
> > +class KGlobalStaticsList: public QList<KGlobalStaticBase*>
> > +{
> > +};
>
> typedef ?

Yes, but then the typedef would have to be in the header file. This is the 
same pattern as used for KStaticDeleterList in order to have a simple forward 
declaration in the header.

> > +class KGlobalStaticBase
> > +{
> > +    public:
> > +        virtual ~KGlobalStaticBase() {}
> > +        virtual void destroy() = 0;
> > +};
>
> The ~KGlobalStaticBase destructor must not be inline  file, see the comment
> in kstaticdeleter.cpp

I'm not sure why KGlobalStaticBase should not be completely inline. I was 
thinking about moving the KGlobal::addGlobalStatic() call to the 
KGlobalStaticBase ctor, though (see new patch).

> >  ~KInstance
> >  {
> > +    KGlobal::deleteGlobalStatics();
>
> Does this works if we have several KInstance (for plugins) ?
> When plugin are unloaded that will remove all singletons... bad

Right. For some reason I was thinking there's only one KInstance per app. So 
the call either needs to be moved to ~KApplication where the KStaticDeleters 
are deleted. (It won't crash, with the call in ~KInstance, but it could 
delete the global statics too early.) Or: see attached patch.

> Also, all of this should be documented.

I'll document it as soon as it's decided that we want to use this. Currently 
I'm not sure that this is the right solution.

-- 
________________________________________________________
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: kglobalstatic.diff
Type: text/x-diff
Size: 9692 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20070117/6c267bba/attachment.diff>
-------------- 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/20070117/6c267bba/attachment.sig>


More information about the kde-core-devel mailing list