One more question to kstaticdelter
Ingo Klöcker
kloecker at kde.org
Tue May 1 09:47:28 BST 2007
On Monday 30 April 2007 23:15, Thiago Macieira wrote:
> Christian Ehrlicher wrote:
> >Hi,
> >
> >kconfig_compiler creates code like this:
> >
> >Settings *Settings::mSelf = 0;
> >static KStaticDeleter<Settings> staticSettingsDeleter;
> >
> >Settings *Settings::self()
> >{
> > if ( !mSelf ) {
> > staticSettingsDeleter.setObject( mSelf, new Settings() );
> > mSelf->readConfig();
> > }
> >
> > return mSelf;
> >}
> >
> >Settings::Settings( )
> >
> > : KConfigSkeleton( QLatin1String( "kgetrc" ) )
> >
> >{
> > mSelf = this;
> > ..
> >
> >}
> >
> >Settings::~Settings()
> >{
> > if ( mSelf == this )
> > staticSettingsDeleter.setObject( mSelf, 0, false );
> >}
> >
> >What's the best way to replace this? I would use a
> > QBasicAtomicPointer and qAddPostRoutine()... but I won't break
> > kconfig_compiler so I ask you
> >
> > :)
>
> Yes, that looks like it's the best option.
>
> However, if someone calls the constructor twice, it leaks memory. So,
> something is wrong.
The constructor is not supposed to be called directly, but only through
self().
> Can someone explain what the code intends to do?
Provide a KConfigXT settings singleton.
Regards,
Ingo
-------------- 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/20070501/a1388dfa/attachment.sig>
More information about the kde-core-devel
mailing list