How to delete all rows from QTableWidget

前端 未结 10 1873
自闭症患者
自闭症患者 2021-01-31 14:57

I am trying to delete all rows from a QTableWidget . Here is what I tried.

for ( int i = 0; i < mTestTable->rowCount(); ++i )
{
    mTestTable->removeRo         


        
10条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-31 15:31

    In order to prevent an app crash, disconnect all signals from the QTableView.

    // Deselects all selected items
    ui->tableWidget->clearSelection();
    
    // Disconnect all signals from table widget ! important !
    ui->tableWidget->disconnect();
    
    // Remove all items
    ui->tableWidget->clearContents();
    
    // Set row count to 0 (remove rows)
    ui->tableWidget->setRowCount(0);
    

提交回复
热议问题