I am looking for a solution of creating paging using QSqlQueryModel.
Problem I am having is I want to use paging in extracting the data from sql db file , for this i have chosen QSqlQueryModel. But now the problem is that I cannot control of how many records it will fetch.
Basically if there are 1000 of records in database and I want only 20 entries to be fetched initially and rest on another call 20 more entries and later on another call 20 more entries and so on. How to do that ?
So far the codes are
QSqlQueryModel *model = new QSqlQueryModel;
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("/Users/xyz/events.db");
if (db.isValid())
{
db.open();
if (db.isOpen())
{
model->setQuery("select * from events");
qDebug() << "I m Working";
QSqlRecord rec = model->record(0);
qDebug() << rec;
qDebug() << model->canFetchMore();
db.close();
} else {
qDebug() << "DB is not open";
}
} else {
qDebug() << "DB is not valid";
}
There is canFetchMore() function in QSqlQueryModel. So if setQuery fetches all the data than it will always be false than how to adjust it that i can use fetchmore() to fetch more data in a controlled manner.
Thank You