QTableView export to .csv number of rows fetched is limited to only 256

落爺英雄遲暮 提交于 2019-11-30 16:08:16
Nejat

I think when you first read model->rowCount() the model has not fetched all the results completely. Although it will fetch more later when table view is displayed resulting in a full display of rows in the table view.

Try to use QSqlQueryModel::fetchMore before reading the row count :

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

int rows=model->rowCount();
int columns=model->columnCount();

[Additional information from Tay2510]:

You could just change the file open flag

if(csvfile.open(QIODevice::WriteOnly|QIODevice::Truncate))

to

if(csvfile.open(QIODevice::WriteOnly))

The former will overwrite the same file while the latter append data on it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!