[Kde-pim] D-Pointer problem

Ingo Klöcker kloecker at kde.org
Sat May 31 22:44:56 BST 2008


On Saturday 31 May 2008, Tom Albers wrote:
> Hi,
>
> I've added d-pointers for two classes in kpimidentities, but i can
> not get it to work properly. The stuff compiles ok, but as soon as i
> open the config from mailody it crashes in the identititymanager.
>
> If i revert the patch for the signature files, it won't crash. This
> is all with recompilation of mailody in between. I've spent some
> hours in trying to fix it, but I failed.
>
> Maybe someone with 'fresh' eyes, is willing to try the patch, see if
> it crashes too and if so spot the error I made.
>
> Diff is attached, please note that 'patch' did not make a very
> readable diff this time.

One thing I noticed is that you have (accidentally) moved the 
initialization of mReadOnly after readConfig().

-  mReadOnly = readonly;
   mConfig = new KConfig( "emailidentities" );
-  readConfig( mConfig );
+  d->readConfig( mConfig );
+  d->readOnly = readonly;


Another thing that might cause problems is that the virtual method 
IdentityManager::createDefaultIdentity() is called (indirectly via 
IdentityManager::Private::createDefaultIdentity()) in the c'tor 
IdentityManager::IdentityManager(). This will not work as expected 
because by the time IdentityManager::IdentityManager() is executed a 
subclass derived from IdentityManager will not yet have been fully 
initialized. But since d->createDefaultIdentity() is called after 
d->readConfig( mConfig ) this does not explain the crash.


I suggest to move mIdentities and mShadowIdentities also to 
IdentityManager::Private. And why is mConfig not in Private? If you 
want to use pimpl then please don't do it half-heartedly.


The following code snippet is really ugly (which isn't your fault):
    q->mIdentities << Identity();
    q->mIdentities.last().readConfig( configGroup );
    if ( !haveDefault && q->mIdentities.last().uoid() == 
defaultIdentity ) {
      haveDefault = true;
      q->mIdentities.last().setIsDefault( true );
    }

Instead of using QList::last() all the time I'd use a temporary 
variable:
    Identity identity;
    identity.readConfig( configGroup );
    if ( !haveDefault && identity.uoid() == defaultIdentity ) {
      haveDefault = true;
      identity.setIsDefault( true );
    }
    q->mIdentities << identity;


Regards,
Ingo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 194 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-pim/attachments/20080531/f8e9ef37/attachment.sig>
-------------- next part --------------
_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/


More information about the kde-pim mailing list