sajis997
3rd December 2014, 16:21
Hi Forum,
Suppose that i define the following class as the subclass of QObject for smarter memory management:
class Shader : public QObject
{
Q_OBJECT
.....................
.....................
};
Then inside the another class definition i declare a pointer of the above type (composite pattern) as follows:
Shader *shade;
And inside the source of the class definition i allocate memory on the heap. Just because i inherited from QObject , will the memory pointed by shade be de-allocated by Qt ?
If this is so , then what is the point of having the following declaration instead?:
QPointer<Shader> shade;
or
QSharedPointer<Shader> shade;
or
QScopedPointer<Shader> shade;
There are few more in the documentation. Lets understand the above first.
Some explanation with code snippet would be very helpful.
Thanks
Suppose that i define the following class as the subclass of QObject for smarter memory management:
class Shader : public QObject
{
Q_OBJECT
.....................
.....................
};
Then inside the another class definition i declare a pointer of the above type (composite pattern) as follows:
Shader *shade;
And inside the source of the class definition i allocate memory on the heap. Just because i inherited from QObject , will the memory pointed by shade be de-allocated by Qt ?
If this is so , then what is the point of having the following declaration instead?:
QPointer<Shader> shade;
or
QSharedPointer<Shader> shade;
or
QScopedPointer<Shader> shade;
There are few more in the documentation. Lets understand the above first.
Some explanation with code snippet would be very helpful.
Thanks