|
1Qter豆
刚开始是可删记录的,但添加一条新记录后,就删不了了,很奇怪的问题
- //添加代码
- QSqlQuery query;
- QString sql="insert into product (name,category,price) values (:name,:category,:price)";
- query.prepare(sql);
- query.bindValue(":name", product.name);
- query.bindValue(":category", product.category);
- query.bindValue(":price", product.price);
- //删除代码
- QModelIndexList list=this->tableview->selectionModel()->selectedIndexes();
- QMap<int, int> rowMap;
- foreach (QModelIndex index, list){
- rowMap.insert(index.row(), 0);
- }
- int rowToDel=0;
- QMapIterator<int, int> rowMapIterator(rowMap);
- rowMapIterator.toBack();
- while (rowMapIterator.hasPrevious())
- {
- rowMapIterator.previous();
- rowToDel = rowMapIterator.key();
- this->sqltablemodel->removeRow(rowToDel);
- }
复制代码
|
|