QtableWidget: How to find value in specific column

旧街凉风 提交于 2019-12-22 08:43:06

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!