0

When creating a class Foo, it is common separate the implementation details/data into a private class FooPrivate.

class Foo { FooPrivate* p; ... };

As far as I can see there are 4 strategies to manage the memory of p;

  1. manually delete in destructor
  2. QObject hierarchy. Make both QObjects and pass Foo as parent to FooPrivate.
  3. Use QScopedPointer.
  4. Use a std smart pointer.
  5. Use QSharedDataPointer. (Useful for big objects you copy a lot)

Best practices can apparently be found here (How to use the Qt's PIMPL idiom?). However, my main question is this. Every QObject has an associated QObject::thread(). Is there a smart pointer that is also a QObject, and that can check its thread is equal to the current thread when it is dereferenced? This would be very useful in preventing threading bugs for me. Would it be possible to implement such a pointer?

yokto
  • 725
  • 4
  • 18

0 Answers0