我需要使用 qtablewidget 检查特定值是否在特定列中。在我的情况下,我需要检查第一列是否已经存在 ID,如果是,我需要包含行的编号来更新该行,否则我想添加该行。QT有没有提供任何解决方案来检查列或shou
问问题
8485 次
1 回答
7
我假设您正在第一列中寻找您的值(这就是为什么 item(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
}
于 2012-09-12T17:25:52.787 回答