kghose
11th August 2008, 20:33
Hi,
I have a regular class A and a class B that inherits from a QGraphicsWidget. class B carries a pointer to A.
class A counts itself - that is a given instance of A can be shared by several other classes. An instance of A can be "attach"-ed to other classes (such as B). When an object pointing to an instance of A gets destroyed it calls "detach". When an instance of A finds that the last call to "detach" has left it with no parents, it deletes itself.
So one would expect that if I create an object of class B and attach an object of class A to it and then delete B first A should be destroyed then B is destroyed.
Now when I try out this logic with straight C++ it works fine. However, when I track my QT based program I see that things happen in batches. That is, I have a list of As and a list of Bs. When I run through the list of Bs deleting them, the Bs get destroyed first as a group and then the As get destroyed second AS A GROUP.
The way I'm noting this is to have print statements in the code. What is happening? Are the delete statements somehow queued when we deal with a Q_OBJECT?
I would really appreciate this puzzler being cleared up :)
Thanks
-K
I have a regular class A and a class B that inherits from a QGraphicsWidget. class B carries a pointer to A.
class A counts itself - that is a given instance of A can be shared by several other classes. An instance of A can be "attach"-ed to other classes (such as B). When an object pointing to an instance of A gets destroyed it calls "detach". When an instance of A finds that the last call to "detach" has left it with no parents, it deletes itself.
So one would expect that if I create an object of class B and attach an object of class A to it and then delete B first A should be destroyed then B is destroyed.
Now when I try out this logic with straight C++ it works fine. However, when I track my QT based program I see that things happen in batches. That is, I have a list of As and a list of Bs. When I run through the list of Bs deleting them, the Bs get destroyed first as a group and then the As get destroyed second AS A GROUP.
The way I'm noting this is to have print statements in the code. What is happening? Are the delete statements somehow queued when we deal with a Q_OBJECT?
I would really appreciate this puzzler being cleared up :)
Thanks
-K