How to delete all rows from QTableWidget

前端 未结 10 2121
自闭症患者
自闭症患者 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:19

    Your code does not delete last row.

    Try this one.

    int totalRow = mTestTable->rowCount();
    for ( int i = 0; i < totalRow ; ++i )
    {
           mTestTable->removeRow(i);
    }
    

    In your code, on the first time, rowCount() have value 2 and value of the i is 0, so its delete 1st row,

    But on the second time value of i incremented with 1, but rowCount() return the updated row count which is now 1, so, it does not delete the last row.

    Hope now you ll be clear.

提交回复
热议问题