Results 1 to 9 of 9

Thread: QList and removeAt() question

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Qt products
    Qt5
    Platforms
    MacOS X
    Thanks
    13
    Thanked 153 Times in 150 Posts

    Default Re: QList and removeAt() question

    You don't show where you delete myList in your code. You should delete in init's counterpart (cleanup?) or your MyClass destructor so that you don't leak memory for the list itself. I would add the following code to do that:

    Qt Code:
    1. myList.clear(); // done by destructor, but doesn't hurt to clear IMHO
    2. delete myList;
    3. myList = nullptr;
    To copy to clipboard, switch view to plain text mode 

    Since you are not storing pointers to objects in your list, I don't see any issues with your handling of MyObjectData.

    P.S. You will crash if your myList is empty when you run this code, so also check that myList->size() > 0 in your if statement.
    Last edited by jefftee; 6th July 2015 at 18:04.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

Similar Threads

  1. QList question
    By DoomerDan in forum Qt Programming
    Replies: 8
    Last Post: 29th January 2015, 16:45
  2. QList Question
    By giblit in forum Qt Programming
    Replies: 2
    Last Post: 4th April 2013, 02:41
  3. QList<QList > question
    By SubV in forum Qt Programming
    Replies: 3
    Last Post: 25th July 2008, 16:14
  4. QList question
    By aamer4yu in forum Qt Programming
    Replies: 4
    Last Post: 2nd April 2007, 14:43
  5. QList question
    By ln\ in forum Newbie
    Replies: 2
    Last Post: 19th December 2006, 14:01

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.