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

Nikos Chantziaras realnc at gmail.com
Wed May 4 19:58:07 CEST 2016


On 04/05/16 18:00, Sean Harmer wrote:
> On Wednesday 04 May 2016 17:48:50 Nikos Chantziaras wrote:
>> Is there a Qt-specific idiom where I can manage QObjects that have a
>> parent with a smart pointer and not have to worry about double-deletion?
>>
>> Or, to phrase it in another way, is there a way to eliminate the 'new'
>> keyword completely from my code-base when using QObjects with a parent?
>
> Use smart pointers to only manage the root objects of your QObject hierarchies
> and rely upon QObject to manage the child objects.

That's not good enough. I need to delete objects way before their parent 
is deleted. Otherwise, for all intents and purposes, I'm leaking memory.




More information about the Interest mailing list