Results 1 to 6 of 6

Thread: Does QTableWidget::clear() delete pointers?

  1. #1
    Join Date
    Sep 2009
    Posts
    64

    Default Does QTableWidget::clear() delete pointers?

    Hey everyone!

    I am working on a QTableWidget and there is alot of data i am adding and refreshing and i was wondering if when i call a QTableWidget::clear() if that will delete the pointers i have created and inserted to the table...

    i dont want any memory leaks!

    any help is greatly appreciated

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Does QTableWidget::clear() delete pointers?

    Yes, as you can see in the sources:
    Qt Code:
    1. void QTableModel::clear()
    2. {
    3. for (int j = 0; j < verticalHeaderItems.count(); ++j) {
    4. if (verticalHeaderItems.at(j)) {
    5. verticalHeaderItems.at(j)->view = 0;
    6. delete verticalHeaderItems.at(j);; // <--
    7. verticalHeaderItems[j] = 0;
    8. }
    9. }
    10. for (int k = 0; k < horizontalHeaderItems.count(); ++k) {
    11. if (horizontalHeaderItems.at(k)) {
    12. horizontalHeaderItems.at(k)->view = 0;
    13. delete horizontalHeaderItems.at(k);; // <--
    14. horizontalHeaderItems[k] = 0;
    15. }
    16. }
    17. clearContents();
    18. }
    19.  
    20. void QTableModel::clearContents()
    21. {
    22. for (int i = 0; i < tableItems.count(); ++i) {
    23. if (tableItems.at(i)) {
    24. tableItems.at(i)->view = 0;
    25. delete tableItems.at(i); // <--
    26. tableItems[i] = 0;
    27. }
    28. }
    29. reset();
    30. }
    To copy to clipboard, switch view to plain text mode 

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

    Neptilo (24th June 2013)

  4. #3
    Join Date
    Sep 2009
    Posts
    64

    Default Re: Does QTableWidget::clear() delete pointers?

    perfect thanks! oh and i got that icon sizing thing to work... fyi

  5. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Does QTableWidget::clear() delete pointers?

    Quote Originally Posted by Slewman View Post
    oh and i got that icon sizing thing to work... fyi
    Fine. Please add your solution to your thread that others can benefit from it.

  6. #5
    Join Date
    Aug 2009
    Posts
    92
    Thanks
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Does QTableWidget::clear() delete pointers?

    From my point of view, clear() has a bug.
    It should not reset the Header but only all the rows of the list.
    I've lost one day in trying to understand the problem and then it was just a call to clear()

  7. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Does QTableWidget::clear() delete pointers?

    Well, then you have to use QTableWidget::clearContents(). And header items are also items of the view, and the headers are connected to the contend I find it reasonable that clear clears both, header and content items.

    Nevertheless, tough luck you lost a day!

Similar Threads

  1. QTableWidget & cellWidget : some pointers
    By prashant in forum Qt Programming
    Replies: 1
    Last Post: 18th October 2009, 10:48
  2. Replies: 2
    Last Post: 13th May 2009, 10:35
  3. Does clear()/clearContents() delete items?
    By vycke in forum Qt Programming
    Replies: 1
    Last Post: 31st July 2008, 17:49
  4. Replies: 1
    Last Post: 14th May 2008, 19:35
  5. How to delete header on QTableWidget
    By jlbrd in forum Qt Programming
    Replies: 2
    Last Post: 18th July 2006, 21:00

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.