我正在尝试更新记录,我有这个:
tableModel->select();
QModelIndex index = ui.tableView->currentIndex();
QString sqlQuery = QString("UPDATE %1 SET firstname=:firstname, lastname=:lastname, country=:country, city=:city WHERE id=:id)").arg(tableName);
query.prepare(sqlQuery);
QSqlRecord recordz = tableModel->record(index.row());
query.bindValue(":firstname", ui.fEdit->text());
query.bindValue(":lastname", ui.lnEdit->text());
query.bindValue(":country", ui.cEdit->text());
query.bindValue(":city", ui.cityEdit->text());
query.bindValue(":id", recordz.value("id").toInt());
query.exec();
tableModel->submitAll();
该应用程序编译没有错误,但它不会保存任何编辑。