Results 1 to 4 of 4

Thread: QTableWidget -- SetItem

  1. #1
    Join Date
    Jul 2008
    Posts
    139
    Thanks
    9
    Thanked 18 Times in 15 Posts
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default QTableWidget -- SetItem

    Hi,
    I created a QTableWidget to illustrate the available wireless networks. The rowCount will be dynamic depending on number of networks. CellList is just text names I create before entering this loop.
    My concern is using the 'new' for the QTableWidgetItem. It is possible this routine to populate the table will be called on a button press to refresh.
    How or when should I delete (release) the memory?
    Will QTableWidget::clearContents() accomplish this?

    Qt Code:
    1. for (int i = 0; i < rowCount; i++ )
    2. {
    3. QTableWidgetItem *__essidName = new QTableWidgetItem(CellList[i][1].at(0));
    4. uiWireless->availableNetworksTable->setItem(i,0,__essidName);
    5. QTableWidgetItem *__strengthValue = new QTableWidgetItem(CellList[i][6].at(0));
    6. uiWireless->availableNetworksTable->setItem(i,1,__strengthValue);
    7. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableWidget -- SetItem

    ya... the clear function will delete the items.. you can always check this by holding a item pointer and then clearcontents.. after that try to use the item.. if you app crashes then the item is deleted

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableWidget -- SetItem

    ya... the clear function will delete the items.. you can always check this by holding a item pointer and then clearcontents.. after that try to use the item.. if you app crashes then the item is deleted
    Better way would be to subclass QTableWidgetItem and put a break point in destructor and check if the destructor is called when clearContents is called.

  4. #4
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTableWidget -- SetItem

    Quote Originally Posted by aamer4yu View Post
    Better way would be to subclass QTableWidgetItem and put a break point in destructor and check if the destructor is called when clearContents is called.
    too much coding for a simple check.. furthermore i like things to burn in horror...

Similar Threads

  1. QTableWidget crashes on setItem
    By Raccoon29 in forum Qt Programming
    Replies: 5
    Last Post: 18th August 2016, 18:48
  2. QComboBox in QTableWidget : display troubles.
    By Nyphel in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2007, 23:29
  3. QTableWidget (resizing rows, turning off selection, etc.)
    By kiss-o-matic in forum Qt Programming
    Replies: 6
    Last Post: 11th January 2007, 01:57
  4. QTableWidget editing question
    By Trasmeister in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2006, 18:46
  5. Replies: 6
    Last Post: 5th March 2006, 21: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
  •  
Qt is a trademark of The Qt Company.