I have a QObject SystemdDBusManager
that can return other QObjects (Unit
class). Those objects do not have any reason to be owned by SystemdDBusManager
, but according to the Qt documentation, this can imply that the returned object is owned by SystemdDBusManager.
class SystemdDBusManager : public QObject
{
Q_OBJECT
public:
Unit *getUnit(QString const &name);
};
What would be a good way to make it clear that the Unit
is not owned by SystemdDBusManager
?
You can return a shared pointer or a unique pointer to the
Unit
object, depending on how you are going to use the object.That way, the caller will not have to care about the lifetime of the pointer.