Results 1 to 4 of 4

Thread: will QHash::remove call delete?

  1. #1
    Join Date
    Jul 2010
    Posts
    63
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default will QHash::remove call delete?

    i have:
    Qt Code:
    1. QHash<QString, polly::Element*> _children;
    To copy to clipboard, switch view to plain text mode 
    (polly::element being a class of my own)

    i want to remove an item from the hash and be sure its dead - the internet has me confused about this one.. will remove call delete for me?

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: will QHash::remove call delete?

    You're storing a pointer to polly::Element so you have to delete yourself.
    A camel can go 14 days without drink,
    I can't!!!

  3. #3
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: will QHash::remove call delete?

    just make a call like this to remove and delete

    Qt Code:
    1. delete _childern.take(key);
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jul 2010
    Posts
    63
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: will QHash::remove call delete?

    EDIT: late response, nish answered

    which one is the better option?
    ( element is also a QObject - just noticed that my QHash of children logically clashes with the QObject's having a children list already.. )

    Qt Code:
    1. delete _children.take( name );
    2.  
    3. _children.value( name )->deleteLater();
    4. _children.remove( name );
    5.  
    6. delete _children.value( name );
    7. _children.remove( name );
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 6
    Last Post: 22nd March 2011, 15:17
  2. delete or remove QDialog?
    By kapitanluffy in forum Newbie
    Replies: 1
    Last Post: 8th February 2011, 16:06
  3. How to use QMap::remove() to delete some item?
    By jedychen in forum Qt Programming
    Replies: 5
    Last Post: 18th September 2008, 07:29
  4. Replies: 16
    Last Post: 13th March 2008, 17:46
  5. Replies: 2
    Last Post: 22nd February 2006, 14:58

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.