windows下QT中如何删除tableview中的选中行

萝卜条 萝卜条 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
如题,纠结这个问题好久了,各位大神们给点意见。。。。。以下是函数代码
void MainWindow::on_deleteButton_clicked()
{
int curRow = ui->tableView->currentIndex().row();

QModelIndex index = ui->tableView->currentIndex();

int id=index.sibling(curRow,4).data().toInt();


QSqlQuery query;

query.prepare("delete from table where id =:id ");

query.bindValue(":id",id);
bool ok=query.exec();
if(ok)
{
qDebug()<<"delete success";
}
else
{
qDebug()<<"delete error"<<query.lastError().text();

}
}
...全文
评论 4
收藏 已收藏
分享
返回顶部
萝卜条
Qt 21,503 成员 26,693 内容