One more question to kstaticdelter

Thiago Macieira thiago at kde.org
Tue May 1 14:19:32 BST 2007


Andreas Pakulat wrote:
>> > > > The constructor is not supposed to be called directly, but only
>> > > > through self().
>> > >
>> > > But this can't be guaranteed because the ctor is not private.
>> >
>> > That seems to be a bug then.
>>
>> As long as ::instance( QStringList ) stays I think thats fine.
>
>Hmm, if kconfig_compiler creates a singleton object then none of the two
>constructors are public, they are protected yes, but that is needed.

If the constructor is private, you can accomplish this task via:

class SettingsPrivate;
class Settings: public ...
{
public:
    [....]
    static Settings *self();
private:
    Settings(const QString &);
    ~Settings();
    friend class SettingsPrivate;
};


class SettingsPrivate
{
    Settings q_ptr;
    [... other privates ...]
};
K_GLOBAL_STATIC(SettingsPrivate, s_self)

Settings *Settings::self()
{
    return &s_self->q_ptr;
}

-- 
  Thiago Macieira  -  thiago (AT) macieira.info - thiago (AT) kde.org
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- 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/c89f5736/attachment.sig>


More information about the kde-core-devel mailing list