Results 1 to 2 of 2

Thread: new e delete

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default new e delete

    hi do anyone wich is correct between two? thanks
    Qt Code:
    1. std::vector <FancyPopup*> ppop;
    2. for (int i=0; i<8; i++)
    3. ppop.push_back(new FancyPopup(this));
    4. for( std::vector <FancyPopup*>::iterator i = ppop.begin(); i != ppop.end(); ++i ) {
    5. delete *i; //or delete [] *i;
    6. }
    7. ppop.clear();
    To copy to clipboard, switch view to plain text mode 
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: new e delete

    You should use the same type of operator for releasing memory as you did for allocating it, so:
    new -> delete
    new [] -> delete []
    malloc() -> free()

    In your case it should be "delete *i";

Similar Threads

  1. When is the best time to delete a QCanvasItem
    By irudkin in forum Qt Programming
    Replies: 12
    Last Post: 8th March 2007, 22:28
  2. delete items from list box
    By vvbkumar in forum Qt Programming
    Replies: 4
    Last Post: 23rd June 2006, 20:08
  3. a simple question .how to delete a treewidgetitem
    By Alina in forum Qt Programming
    Replies: 6
    Last Post: 20th February 2006, 11:18
  4. Basic question on new and delete
    By jcr in forum General Programming
    Replies: 25
    Last Post: 14th February 2006, 16:09
  5. How to explicitely delete a QDir?
    By alan in forum Newbie
    Replies: 2
    Last Post: 13th February 2006, 18:48

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.