QSqlQueryModel ‘s method rowcount() return 256
there are 1000 record in my database table,but when i use querymodel binding the tableview, there are 1000 records displaying in the tableview,but the querymodel.rowcount() return 256,why?thanks! the code as follows:
Code:
QString querystr
= "select * from mytable";
query.exec();
model->setQuery(query);
model->setHeaderData(1, Qt::Horizontal, tr("name"));
model->setHeaderData(2, Qt::Horizontal, tr("age"));
ui->tableViewZDCommTask->setModel(model);
ui->tableViewZDCommTask->setColumnHidden(0,true);
ui->tableViewZDCommTask->resizeColumnsToContents();
QHeaderView *header
= ui
->tableViewZDCommTask
->horizontalHeader
();
header->setStretchLastSection(true);
ui->tableViewZDCommTask->show();
Re: QSqlQueryModel ‘s method rowcount() return 256
Did You read how this method work ? Doc says : If the database supports returning the size of a query (see QSqlDriver::hasFeature()), the number of rows of the current query is returned. Otherwise, returns the number of rows currently cached on the client..
As you can see the result is dependent on what can your database.
Re: QSqlQueryModel ‘s method rowcount() return 256
QSqlQueryModel, on which QTableModel is built, is hard coded to prefetch 255 rows at a time. Look at the canFetchMore() and fetchMore() methods.