How to delete all rows from QTableWidget

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

    I don't know QTableWidget but your code seems to have a logic flaw. You are forgetting that as you go round the loop you are decreasing the value of mTestTable->rowCount(). After you have removed one row, i will be one and mTestTable->rowCount() will also be one, so your loop stops.

    I would do it like this

    while (mTestTable->rowCount() > 0)
    {
        mTestTable->removeRow(0);
    }
    

提交回复
热议问题