windows下QT中如何删除tableview中的选中行
萝卜条 2014-10-20 07:18:01 如题,纠结这个问题好久了,各位大神们给点意见。。。。。以下是函数代码
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();
}
}