Results 1 to 5 of 5

Thread: QVector clear()

  1. #1
    Join Date
    Dec 2007
    Posts
    19
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QVector clear()

    Hi,

    I have a Vector containing GeometricObject pointers. (3d objects I use in my raytracer program). I was wondering if when I call clear() on the vector, only the items of the vector are destroyed or also the GeometricObjects itself are deleted?

    Or do I have to clean the pointers and delete the GeometricObjects to avoid memory leaks manually?

  2. #2
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QVector clear()

    Of course you have to.
    Since clear delete the objects managed by your container, it deletes only the pointer and not the objects pointed.

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QVector clear()

    The qDeleteAll() function from QtAlgorithms might become handy...
    J-P Nurmi

  4. #4
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QVector clear()

    Or maybe your objects are managed by a parent, like a lot of widgets in Qt class hierachy, that are deleted by the owner.

  5. #5
    Join Date
    Dec 2007
    Posts
    19
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QVector clear()

    Nope, they are my own objects (no QObjeccts). But QtAlgorithms looks handy ;-)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.