I'm starting to use the Pimpl idiom (aka cheshire cat, d-pointer) but I'm getting segfaults in my destructors under certain conditions. Let me try to explain:

Qt Code:
  1. //MYCLASS.H
  2.  
  3. class MyClassPrivate;
  4.  
  5. class MyClass {
  6. public:
  7. MyClass();
  8. MyClass(const MyClass &other);
  9. ~MyClass();
  10.  
  11. private:
  12. MyClassPrivate *d;
  13. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. //MYCLASS.CPP
  2. #include "myclass.h"
  3. #include <QString>
  4. #include <QMap>
  5.  
  6. class MyClassPrivate {
  7. public:
  8. QString mystring;
  9. QMap<QString, int> mymap;
  10. };
  11.  
  12. MyClass::MyClass()
  13. : d(new MyClassPrivate)
  14. { }
  15.  
  16. MyClass:MyClass(const MyClass &other)
  17. : d(newMyClassPrivate(*other.d))
  18. { }
  19.  
  20. MyClass::~MyClass()
  21. {
  22. delete d;
  23. }
To copy to clipboard, switch view to plain text mode 

I have another class, let's call it MyContainerThingy that also uses Pimpl and stores a MyClass value:

Qt Code:
  1. //MYCONTAINERTHINGY.H
  2.  
  3. class MyContainerThingyPrivate;
  4.  
  5. class MyContainerThingy {
  6. public:
  7. MyContainerThingy();
  8. MyContainerThingy(const MyContainerThingy &other);
  9. ~MyContainerThingy();
  10.  
  11. private:
  12. MyContainerThingyPrivate *d;
  13. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. //MYCONTAINERTHINGY.CPP
  2. #include "mycontainerthingy.h"
  3. #include "myclass.h"
  4.  
  5. class MyContainerThingyPrivate {
  6. public:
  7. MyClass myclass;
  8. };
  9.  
  10. MyContainerThingy::MyContainerThingy()
  11. : d(new MyContainerThingyPrivate)
  12. { }
  13.  
  14. MyContainerThingy:MyContainerThingy(const MyContainerThingy &other)
  15. : d(newMyContainerThingyPrivate(*other.d))
  16. { }
  17.  
  18. MyContainerThingy::~MyContainerThingy()
  19. {
  20. delete d;
  21. }
To copy to clipboard, switch view to plain text mode 

These two classes are compiled into a shared library. When I attempt to use these classes from my application it segfaults with the following frame stack (from KDevelop3 debugging via gdb):

Qt Code:
  1. #0 QBasicAtomicInt::deref
  2. #1 ~QMap
  3. #2 ~MyClassPrivate
  4. #3 ~MyClass
  5. #4 ~MyContainerThingy
  6. #5 ~MyContainer
  7. #6 main
To copy to clipboard, switch view to plain text mode 

And it's not only QMap, but QHash, QString as well.

Any ideas?