I Have a qtableWidget and must delete all existing rows when click a button, I am trying as follows, but it only deletes one row at a time
Code:
for (int i = 0; i < ui.tableWidget->rowCount(); i++) ui.tableWidget->removeRow(i);
Printable View
I Have a qtableWidget and must delete all existing rows when click a button, I am trying as follows, but it only deletes one row at a time
Code:
for (int i = 0; i < ui.tableWidget->rowCount(); i++) ui.tableWidget->removeRow(i);
Is this the real and full code?
Post few lines before and after as well please.
try "clear" (delete all the items) or "clearContents" (delete all the items but the headers)
So try "clear"... as far as I remember, it deletes all, even the lines.
It erases all the same, including the column names
there is no other way?
Or how do I put the names in the columns again? (I named the columns using the QTDesigner)
lol
Thanks
I tried this, but the program simply fails (crash) if I try to rename the columns
Code:
ui.tableWidget->clear(); ui.tableWidget->horizontalHeaderItem(0)->setText("Name"); ui.tableWidget->horizontalHeaderItem(1)->setText("IP/DNS"); ui.tableWidget->horizontalHeaderItem(2)->setText("Phone"); ui.tableWidget->horizontalHeaderItem(3)->setText("Situation");
I think you delete the headers when you use "clear", so you need to create them again.
Something like:
Code:
ui.tableWidget->setHorizontalHeaderItem(0, pHeader1); ui.tableWidget->setHorizontalHeaderItem(1, pHeader2); //etc
I solved my problem:
Code:
for(int i = ui.tableWidget->rowCount() - 1; i >= 0; i--){ ui.tableWidget->removeRow(i); }
Thanks :D
QTableWidget::setRowCount() will remove rows to decrease the row count. Set it to zero...