I don’t think there is a good solution to this problem, except to start refactoring your code so that any given object is controlled through parent / child relations like QObject, or shared_ptr <> reference counting, but never in both objects. These two approaches are too different from each other to easily come to terms.
, , , , : , shared_ptr < > , QObject, shared_ptr (- QObject), -, shared_ptr QObject.
:
class MyQObject : public QObject
{
public:
MyQObject(int x, int y, int z, QObject * parent)
: QObject(parent), m_x, m_y, m_z {}
int getX() const {return m_x;}
int getY() const {return m_y;}
int getZ() const {return m_z;}
private:
int m_x, m_y, m_z;
};
[...]
QObject * parent = new QObject;
shared_ptr<MyQObject> ptr(new MyQObject(1,2,3,parent));
- :
class MyData
{
public:
MyData(int x, int y, int z) : m_x(x), m_y(y), m_z(z)
int getX() const {return m_x;}
int getY() const {return m_y;}
int getZ() const {return m_z;}
private:
int m_x, m_y, m_z;
};
class MyQObject : public QObject
{
public:
MyQObject(int x, int y, int z, QObject * parent)
: QObject(parent), m_data(make_shared<MyData>(x,y,z)) {}
int getX() const {return m_data->getX();}
int getY() const {return m_data->getY();}
int getZ() const {return m_data->getZ();}
shared_ptr<MyData> getData() {return m_data;}
private:
shared_ptr<MyData> m_data;
};
[...]
QObject * parent = new QObject;
QObject * myObj = new MyQObject(1,2,3,parent));
shared_ptr<MyData> ptr(myObj->getData());
, Qt QObject, MyData, shared_ptr MyData. (, shared_ptr QObject, , , , Qt , QObject, shared_ptr)