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

  • 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));
    ... a lot more of these

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

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

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.