[Qt-interest] QSqlQueryModel with QSortFilterProxyModel doesn't update properly

Daniël de Kok me at danieldk.eu
Mon Jan 17 16:27:32 CET 2011


Dear list,

I ran into some surprising behavior that I cannot seem to work around. We use QSqlQueryModel in conjunction with a SQLite database, proxied through QSortFilterProxyModel to apply a QRegExp-based filter. When a filter is used, matching records are not shown in the QListView until some (or a lot, depending on the size of the query result set) mouse scrolling is applied.

The models are set up in the following manner:

---
d_sentenceModel = QSharedPointer<QSqlQueryModel>(new QSqlQueryModel);
d_proxySentenceModel = QSharedPointer<QSortFilterProxyModel>(new QSortFilterProxyModel);
d_proxySentenceModel->setSourceModel(d_sentenceModel.data());
d_proxySentenceModel->setFilterKeyColumn(0);
d_minerMainWindow.sentenceView->setModel(d_proxySentenceModel.data())
---

An example query:

---
QSqlQuery sentenceQuery;
sentenceQuery.prepare("SELECT sentences.sentence FROM sentences"
  " WHERE sentences.unparsable = 'true'");
sentenceQuery.exec();
d_sentenceModel->setQuery(sentenceQuery);
---

Is this related to how rowCount is implemented for SQLite? When applying:

---
while(d_sentenceModel->canFetchMore())
  d_sentenceModel->fetchMore();
---

After setQuery(), all matching records are shown. However, this is not a viable approach for us - the database is fairly large and lazy fetching by QSqlQueryModel/QListView is a desired property of this application.

With kind regards,
Daniël de Kok


More information about the Qt-interest-old mailing list