Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Moved] does QTableWidget::clear() also delete QTableWidgetItems ?
Qt 6.11 is out! See what's new in the release blog

[Moved] does QTableWidget::clear() also delete QTableWidgetItems ?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 7.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bergerbits
    wrote on last edited by
    #1

    I have a QTableWidget which I dynamically build and re-biuld.
    I call MyClass::reset() on every re-build where I do QTableWidget::clear ().
    Does that also clear (ie free memory) for every QTableWidgetItem constructed for table's cells?
    Or do I need to delete these explicitly?

    Here's a code snippet

    QTableWidget *tableWidget_channels;

    ...

    QTableWidgetItem *ChannelItem = new QTableWidgetItem(tr("%1").arg(chan+1));
    tableWidget_channels->setItem(nextRow,mChannelCol,ChannelItem);
    ... a lot more of these

    void MyClass::reset()
    {
    ...
    tableWidget_channels->clearContents(); // are items deleted too?
    }

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Franzk
      wrote on last edited by
      #2

      QTableWidget takes ownership of these items, so you can rely on the items being deleted properly.

      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved