Fetch entire result set at once with QSqlRelationalTableModel + QTableView

80 Views Asked by At

I have a QTableView with a QSqlRelationalTableModel as the model. Essentially:

QSqlRelationalTableModel *theModel = ...;
QTableView *theView = ...;

theModel->setTable("table");
theView->setModel(theModel);
theModel->select();

It seems, though, that select() doesn't load the entire result set at once. Rather, it fetches a portion, and then fetches more as I scroll towards the bottom of the table view.

Usually this is what I'd want to happen, but for this particular application I'd like to fetch the entire result set (instead of a portion at a time) so that the view is immediately populated with the full set without any scrolling or other interaction required.

Is there a way to make this happen?

That is, is there a way to get the view/model to grab the complete result set right off the bat?

I'm using Qt 5.15.2, and currently using the QSQLITE driver.

1

There are 1 best solutions below

1
On BEST ANSWER

This is properly described in the documentation: To force fetching of the entire result set, you can use the following:

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