how to remove Item in Qtablewidget?
-
Hi. Guys!
My source code ↓
ui->tableWidget->setItem(0,0,new QTableWidgetItem(QString::number(3)));
ui->tableWidget->item(0,0)->setTextAlignment(Qt::AlignCenter);
My approach :delete ui->tableWidget->item(0,7);
If this memory is free?
If not, let me know any other method.
-
@ForestPoem
Is this the same Question? -
@Ratzz
Thanks, but
That's right, but that's the not answer.
i'dont know item.I call the function each time the button clicked.
connect(ui->tableWidget, SIGNAL(clicked()), this, SLOT(settarget()));
void TargetSet::settarget(){
for(int i=0;i<ui->tableWidget->rowCount();i++){
ui->tableWidget->setItem(i,0,new QTableWidgetItem(QString::number(i));
ui->tableWidget->item(i,0)->setTextAlignment(Qt::AlignCenter);
}
}When you do this, it will be a memory leak.
For this reason, I would like to know the remove -
Hi,
Why not just update the text of your items ?
Otherwise takeItem + delete on the item returned.
-
Using setText will avoid useless delete/allocation of items.