[Qt-interest] QSqlQueryModel with QSortFilterProxyModel doesn'tupdate properly

Scott Aron Bloom Scott.Bloom at onshorecs.com
Mon Jan 17 17:54:04 CET 2011


QSqlQueryModel does not download/receive all the matching rows at once.. what you are seeing is the effects of this...

One way to fix this is after you call setQuery (after calling query.exec() ) is to do a 
While( model->canFetchMore() ) { model->fetchMore(); }

However, for large SQL queries this can be quite a few iterations.  

If possible, move your filter into the WHERE clause of the SQL cmd.

Scott


-----Original Message-----
From: qt-interest-bounces+scott.bloom=onshorecs.com at qt.nokia.com [mailto:qt-interest-bounces+scott.bloom=onshorecs.com at qt.nokia.com] On Behalf Of Daniël de Kok
Sent: Monday, January 17, 2011 7:28 AM
To: qt-interest at qt.nokia.com
Subject: [Qt-interest] QSqlQueryModel with QSortFilterProxyModel doesn'tupdate properly

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
_______________________________________________
Qt-interest mailing list
Qt-interest at qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-interest



More information about the Qt-interest-old mailing list