make KLibrary's kde3Factory behave like kde4Factory

Matthias Kretz kretz at kde.org
Thu Oct 11 12:58:57 BST 2007


On Thursday 11 October 2007, Thiago Macieira wrote:
> Em Thursday 11 October 2007 11:28:09 Matthias Kretz escreveu:
> > #define K_EXPORT_COMPONENT_FACTORY( libname, factory ) \
> > extern "C" { KDE_EXPORT KLibFactory *init_##libname() \
> > { \
> >   static QPointer<QObject> _instance; \
> >   if (!_instance) _instance = new factory; \
> >   return _instance; \
> > } }
> >
> > then init_##libname would behave exactly as qt_plugin_instance and
> > kde3Factory would need no further changes...
> >
> > Comments?
>
> Yes.
>
> The above code is not possible. QPointer is not POD, so it won't be
> initialised and you can't use it like that above.
>
> You can use a K_GLOBAL_STATIC though, but the code becomes very, very ugly.

This is from qplugin.h:
#define Q_PLUGIN_INSTANCE(IMPLEMENTATION) \
        { \
            static QPointer<QObject> _instance; \
            if (!_instance)      \
                _instance = new IMPLEMENTATION; \
            return _instance; \
        }

And why would a local static of non-POD type be a problem, the local static of 
K_GLOBAL_STATIC is also non-POD...

-- 
________________________________________________________
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: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20071011/0959bff9/attachment.sig>


More information about the kde-core-devel mailing list