Results 1 to 4 of 4

Thread: QObject subclass in a QList

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2010
    Posts
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Maemo/MeeGo

    Default Re: QObject subclass in a QList

    Thx for you fast replay.

    And what about memory of the QList<*> ?
    Do i have to manage memory of the QList's data?

    Can someone give me a guide about memory management of Qt? So do i have to delete pointers of QObjects or not?

    Rich

  2. #2
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QObject subclass in a QList

    You have to delete everything yourself, except that QObject deletes all its children itself.

    So for example when you add a widget to a layout, the layout becomes parent of that widget and deletes the widget when it is destroyed.

    But you need to delete your custom objects yourself.

    Your list will probably be a member variable of some object. in its destructor you call:

    Qt Code:
    1. // iterates through all items of the list and calls delete on them, but does not remove the entry from the list!
    2. qDeleteAll(list);
    3. // removes all entries from the list.
    4. list.clear();
    To copy to clipboard, switch view to plain text mode 
    Joh

Similar Threads

  1. Replies: 4
    Last Post: 20th August 2010, 13:54
  2. Replies: 8
    Last Post: 12th February 2010, 02:41
  3. Copying an QList into a new, sorted QList.
    By Thomas Wrobel in forum Newbie
    Replies: 3
    Last Post: 11th January 2010, 18:27
  4. QList: Out of memory - without having defined QList
    By miroslav_karpis in forum Qt Programming
    Replies: 1
    Last Post: 27th March 2009, 08:42
  5. QList<QList > question
    By SubV in forum Qt Programming
    Replies: 3
    Last Post: 25th July 2008, 15:14

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.