How to hide private implementation (implicit sharing) in Qt:
I have Employee.cpp the following in the Employee.h header:
#include <QSharedData> #include <QString> class EmployeeData; class Employee: public QObject { Q_OBJECT public: Employee(); Employee(int id, QString name); Employee(const Employee &other); void setId(int id); void setName(QString name); int id(); QString name(); private: QSharedDataPointer<EmployeeData> d; }; class EmployeeData : public QSharedData { public: EmployeeData() : id(-1) { name.clear(); } EmployeeData(const EmployeeData &other) : QSharedData(other), id(other.id), name(other.name) { } ~EmployeeData() { } int id; QString name; };
But when I move EmployeeData to the private part, say Employee.cpp, I get: error: invalid use of incomplete type 'struct EmployeeData p>
However, if I change my definition to this, it works fine:
class Employee { public: Employee(); Employee(int id, QString name); ..
So, can I use QSharedData when inheriting from QObject?
source share