Results 1 to 4 of 4

Thread: strange delete occurance

  1. #1
    Join Date
    Apr 2011
    Posts
    195
    Thanks
    49
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default strange delete occurance

    Hi, I have a problem I don't understand the behaviour.

    I have a slot and there a instantiate a QList<int*>*;

    Qt Code:
    1. void Class::slot()
    2. {
    3. QList<int>* list = new QList<int>();
    4. qDebug() << "list_adress: " << list; //i.e. 0x7fbc24034870
    5. deleteList(list);
    6. qDebug() << "list_adress: " << list; // i expect 0x0, but output is 0x7fbc24034870
    7. }
    8.  
    9. void Class::deleteList(QList<int>* list)
    10. {
    11. delete list;
    12. list = NULL;
    13. }
    To copy to clipboard, switch view to plain text mode 
    Why pointer is not deleted in slot?
    Please help me!!??

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: strange delete occurance

    It is deleted. It's just not nulled, because you are nulling a copy of the pointer. And next time please post in the right forum, it is not a Qt issue.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    Qiieha (31st May 2012)

  4. #3
    Join Date
    May 2012
    Posts
    136
    Thanks
    2
    Thanked 27 Times in 24 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: strange delete occurance

    Try this:
    Qt Code:
    1. void Class::slot()
    2. {
    3. QList<int>* list = new QList<int>();
    4. qDebug() << "list_adress: " << list; //i.e. 0x7fbc24034870
    5. deleteList(&list);
    6. qDebug() << "list_adress: " << list; // i expect 0x0, but output is 0x7fbc24034870
    7. }
    8.  
    9. void Class::deleteList(QList<int>** list)
    10. {
    11. delete *list;
    12. *list = NULL;
    13. }
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to StrikeByte for this useful post:

    Qiieha (31st May 2012)

  6. #4
    Join Date
    Apr 2011
    Posts
    195
    Thanks
    49
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: strange delete occurance

    @wysota: sorry...and thanks

Similar Threads

  1. About new and delete?
    By yangyunzhao in forum Qt Programming
    Replies: 9
    Last Post: 1st July 2009, 07:06
  2. Replies: 4
    Last Post: 19th February 2009, 11:10
  3. Occurance of Duplicate items in QComboBox
    By merry in forum Qt Programming
    Replies: 8
    Last Post: 12th September 2007, 15:05

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.