[Interest] What's the recommended way to put QObjects in smart pointers?

Nikos Chantziaras realnc at gmail.com
Thu May 5 03:22:31 CEST 2016


On 05/05/16 01:44, Nye wrote:
>
>  > From what I can tell, QPointer does not delete the object, so that's
> a no go.
>
> No one said it does. Perhaps I'm misunderstanding, are you searching for
> a silver bullet for memory management?

I already found it. Question is how to make Qt work with it :-)


>  > That's not good enough. I need to delete objects way before their
> parent is deleted.
>
> So delete them. As I said, parent is notified of the child's deletion.

If I delete them, the parent may already have deleted them. So I'd have 
a double-delete.


>  > When 'parent' gets deleted before 'dialog', then 'dialog' gets
> deleted even though it's on the stack.
>
> And how does the parent gets deleted before the 'dialog' if I may ask,
> unless you're doing deletions from different threads ...?

I don't know. There's long call chains. Someone may delete the parent. 
There's no way to know.

Anyway, the question was whether Qt had something already in place. I 
now see I have to roll my own solution.




More information about the Interest mailing list