From 3c2733e45f7ce0ce9a626d1347bb83ddc41013b2 Mon Sep 17 00:00:00 2001 From: Mark Brand Date: Mon, 17 Sep 2012 14:23:17 +0200 Subject: [PATCH] QSqlTableModel::selectRow(): reduce scope of QSqlQuery It's good to clean up the query before emitting signals about the updated row. It's possible that connected slots will call selectRow() again for other rows. Change-Id: I482fe2dd58218f53567ce8725ee591ce2eeda348 Reviewed-by: Andy Shaw Reviewed-by: Mark Brand --- src/sql/models/qsqltablemodel.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/sql/models/qsqltablemodel.cpp b/src/sql/models/qsqltablemodel.cpp index fbd9207741..f442039d08 100644 --- a/src/sql/models/qsqltablemodel.cpp +++ b/src/sql/models/qsqltablemodel.cpp @@ -431,13 +431,15 @@ bool QSqlTableModel::selectRow(int row) d->sortColumn = table_sort_col; d->filter = table_filter; - QSqlQuery q(d->db); - q.setForwardOnly(true); - if (!q.exec(stmt)) - return false; + { + QSqlQuery q(d->db); + q.setForwardOnly(true); + if (!q.exec(stmt)) + return false; - bool exists = q.next(); - d->cache[row].refresh(exists, q.record()); + bool exists = q.next(); + d->cache[row].refresh(exists, q.record()); + } emit headerDataChanged(Qt::Vertical, row, row); emit dataChanged(createIndex(row, 0), createIndex(row, columnCount() - 1));