Solved Passing QScopedPointer to a member object
-
Hello,
Is it possible to pass /share a member QScopedPointer to another member object ?
example :
class myClass : public QObject { public : // ctor explicit myClass (QObject *parent = nullptr){ handler = new CommunicationHandler; handler->setClient(&myClient); // is this possible ? how to implement the "setClient()" method in CommunicationHandler pls ? } private : CommunicationHandler *handler; QScopedPointer<QOpcUaClient> myClient; }
thank you
-
QScopedPointer has a data() function. Or use a shared pointer or non at all (in this case I don'T see a reason to use one and your example passes an empty pointer so nothing will happen). Passing a pointer to a QScopedPointer is really bad design.
-
QScopedPointer has a data() function. Or use a shared pointer or non at all (in this case I don'T see a reason to use one and your example passes an empty pointer so nothing will happen). Passing a pointer to a QScopedPointer is really bad design.
-
@Christian-Ehrlicher hi
Thank you very much for your answer.this works as i expect, but are you saying this is bad design ?
//CommunicationHandler class, needs a pointer to QOpcUaClient QOpcUaClient* m_uaClient; void setUaClient(QOpcUaClient *uaClient){ m_uaClient = uaClient; }
// base class where CommunicationHandler is created protected: QScopedPointer<QOpcUaClient> m_client; [...] { handler = new CommunicationHandler; handler->setUaClient(m_client.data()); }
-
@LeLev said in Passing QScopedPointer to a member object:
but are you saying this is bad design ?
no, I did not say that this is bad design.
-
@Christian-Ehrlicher
ok good. Thanks