QtableWidget:如何在特定列中查找值

QtableWidget: How to find value in specific column

本文关键字:查找 QtableWidget      更新时间:2023-10-16

我需要使用qtablewidget检查特定值是否在特定列中。在我的情况下,我需要检查第一列ID是否已经存在,如果是,我需要包含行的编号来更新此行,否则我想添加该行。QT是否提供任何解决方案来检查柱或寿

我假设您在第一列中查找值(这就是为什么项(int,int)中的第二个参数为0),表名为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
}