[Qt-interest] does QT have a garbage collector ?

Andreas Pakulat apaku at gmx.de
Mon Mar 2 11:27:29 CET 2009


On 02.03.09 15:41:14, knowledge seeker wrote:
> Hi,
> 
> I have just now started gettting a glimpse of how to make small
> programs in QT; out of curosity I wanted to know that whether creating
> QWidget objects on heap (using new - operator) require explicit call
> to delete, when objects are no longer needed.
> 
> Or we can follow "create-and-forget" paradigm, and QT framework is
> resposible for the deletion of the object by means of some automatic
> garbage collector ?

No there's no garbage collector, but to a certain extent Qt manages
objects. In particular child objects. All QObject subclasses in Qt allow to
pass a parent object to the constructor, if you do this these childs will
automatically be deleted as soon as the parent is deleted. So if you create
complex widgets you don't need to care for all the child wigdets, just
delete the top-most parent and thats it. However that one you have to
delete by yourself.

Andreas

-- 
You like to form new friendships and make new acquaintances.



More information about the Qt-interest-old mailing list