Results 1 to 7 of 7

Thread: setAutoDelete(bool) in Qlist

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2006
    Posts
    211
    Thanks
    27
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question setAutoDelete(bool) in Qlist

    Hi all,

    I m using QT 4.2.2 on my Intel Mac.
    Earlier I m using Qt 3.3 in which I have used the function setAutoDelete(bool) of QPtrList.
    Now I m using QList in Qt 4.2.2 in which I cannot use QPtrList so I m using QList instead of that.

    Now how can I use the setAutoDelete function of QListPtr in Qlist or there is osme other function in Qt 4.2.2 for that.

    Thanks.

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

    Default Re: setAutoDelete(bool) in Qlist

    qDeleteAll()

  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: setAutoDelete(bool) in Qlist

    Porting to Qt 4 - QPtrList<T>
    If you use QPtrList's auto-delete feature (by calling QPtrList::setAutoDelete(true)), you need to do some more work. You have two options: Either you call delete yourself whenever you remove an item from the container, or you can use QList<T> instead of QList<T *> (i.e. store values directly instead of pointers to values).
    qDeleteAll() from QtAlgorithms might be handy..
    J-P Nurmi

  4. #4
    Join Date
    Dec 2006
    Posts
    211
    Thanks
    27
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question Re: setAutoDelete(bool) in Qlist

    Thanks.

    But I donot know how to use it.
    QList<TREEITEM *>list;
    When I m using this like
    list.qDeleteAll()
    then it is giving error that QList<TREEITEM *> has no member name qDeleteAll().

    Plz describe how I can use it.

    Thanks.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setAutoDelete(bool) in Qlist

    Quote Originally Posted by vishal.chauhan View Post
    But I donot know how to use it.
    QList<TREEITEM *>list;
    When I m using this like
    list.qDeleteAll()
    then it is giving error that QList<TREEITEM *> has no member name qDeleteAll()
    qDeleteAll() is a function, so you call it like this:
    Qt Code:
    1. qDeleteAll( list );
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Dec 2006
    Posts
    211
    Thanks
    27
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: setAutoDelete(bool) in Qlist

    Thanks to all of you.
    Now I m using this function.

  7. #7
    Join Date
    Jan 2006
    Location
    Cambridge, MA
    Posts
    32
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: setAutoDelete(bool) in Qlist

    You can also emulate autoDelete when removing items one at a time:

    instead of list.remove(i) use

    delete list.takeAt(i);

    --Justin

Similar Threads

  1. Query about QHash , QList
    By aamer4yu in forum Qt Programming
    Replies: 3
    Last Post: 14th December 2006, 09:04
  2. QList crash in destructor
    By mclark in forum Newbie
    Replies: 7
    Last Post: 6th December 2006, 15:27
  3. QList usage in place QPtrList
    By darpan in forum Qt Programming
    Replies: 2
    Last Post: 25th October 2006, 15:41
  4. Accessing QList Objects
    By magikalpnoi in forum Qt Programming
    Replies: 7
    Last Post: 21st September 2006, 20:43
  5. Values not being appended in a QList
    By Kapil in forum Newbie
    Replies: 5
    Last Post: 21st April 2006, 10:20

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.