问题
I need to check wether a specific value is in a specific column using qtablewidget. In my case I need to check the first column wether an ID is allready existing, if yes I need the number of the containing row to update this row otherwise I like to add the row. Is there any solution provided by QT to check the column or shou
回答1:
I assume that you are looking for your value in first column (that why second argument in item(int,int) is 0) and table name is myQTableWidget
int rows = myQTableWidget->rowCount();
bool found = false;
for(int i = 0; i < rows; ++i)
{
if(myQTableWidget->item(i, 0)->text() == "Something")
{
//we have found our value so we can update 'i' row
found = true;
break;
}
}
if(!found)
{
//we didn't find our value, so we can insert row
}
来源:https://stackoverflow.com/questions/12392395/qtablewidget-how-to-find-value-in-specific-column