Results 1 to 10 of 10

Thread: crash when delete QTreeWidgetItem*

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2006
    Posts
    48
    Thanks
    5
    Thanked 4 Times in 3 Posts

    Post crash when delete QTreeWidgetItem*

    my code:
    Qt Code:
    1. QList<QTreeWidgetItem*>::iterator itd = itemsToDelete.begin();
    2. while (itd != itemsToDelete.end())
    3. {
    4. QTreeWidgetItem* twi_ = *itd;
    5. if (!twi_->childCount())
    6. {
    7. cout <<twi_<<"-"<<twi_->childCount()<<endl; //log1
    8. cout <<twi_->text(0).toStdString()<<endl; //log2
    9. delete twi_;
    10. twi_ = 0;
    11. //twi_->setText(0, "ChangeText"); //if comment "delete twi_;" this line work
    12. cout <<"ok"<<endl;
    13. itd = itemsToDelete.erase(itd);
    14. cout <<"from List ok"<<endl;
    15. }
    16. else
    17. ++itd;
    18. }
    To copy to clipboard, switch view to plain text mode 

    now program log:
    log1: 0x41617880-0 //normal - no children
    log2: itemText // it's right too;

    on line "delete twi_;" program crash (debugger mark this line too)
    why it can be possible?

    P.S my qt version 4.1.4
    more precise: crashing only for non topLevelItems
    Last edited by evgenM; 6th December 2006 at 13:26.

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, 21:28
  2. c++, placement delete upon exception
    By stinos in forum General Programming
    Replies: 6
    Last Post: 31st October 2006, 15:38
  3. Delete all members in a QGraphicsItemGroup
    By vmferreira in forum Qt Programming
    Replies: 3
    Last Post: 17th August 2006, 18:47
  4. QListWidget + Delete Key
    By bpetty in forum Newbie
    Replies: 5
    Last Post: 16th August 2006, 20:38
  5. How to explicitely delete a QDir?
    By alan in forum Newbie
    Replies: 2
    Last Post: 13th February 2006, 17: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
  •  
Qt is a trademark of The Qt Company.