QSqlTableModel: fix segfault when overriding selectRow()
authorMark Brand <mabrand@mabrand.nl>
Tue, 25 Sep 2012 21:50:01 +0000 (23:50 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Fri, 5 Oct 2012 01:16:12 +0000 (03:16 +0200)
commit5fe272f68a59724022f545ac15c2f7d758c5ea86
tree8824c1a0c6afd0dd858473c13404c3b8f4c90d45
parentc86ed49a7989adb3e2e3c42794e44609f12ce493
QSqlTableModel: fix segfault when overriding selectRow()

The STL-style iteration over the cache in submitAll() assumed the
iterator would remain valid until reaching cache.end(). This failed
to consider that virtual selectRow() might be overridden so that
it removes rows from the cache. For example, it might call select()
which would empty the cache.

The new approach checks at each iteration whether the row is
still in the cache. Using foreach here is justified by its fitness
for purpose and readability.

New test included.

Change-Id: Idee8807ede239c3ba56ff1604574c49f47385ad2
Reviewed-by: David Faure (fixes for KDE) <faure@kde.org>
src/sql/models/qsqltablemodel.cpp
tests/auto/sql/models/qsqltablemodel/tst_qsqltablemodel.cpp