gpt4 book ai didi

c++ - QtableWidget : How to find value in specific column

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:38:09 26 4
gpt4 key购买 nike

我需要使用 qtablewidget 检查特定值是否在特定列中。在我的例子中,我需要检查第一列 ID 是否已经存在,如果是,我需要包含行的编号来更新该行,否则我想添加该行。QT有没有提供查列或者shou的解决方案

最佳答案

我假设您正在寻找第一列中的值(这就是为什么 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
}

关于c++ - QtableWidget : How to find value in specific column,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12392395/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com