QTableView导出到.csv获取的行数限制为仅256 [英] QTableView export to .csv number of rows fetched is limited to only 256

查看:1872
本文介绍了QTableView导出到.csv获取的行数限制为仅256的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个gui程序,它将在输入查询后连接到一个oracle db检索数据。检索的数据显示在QTableView表模型窗口小部件中。后来将QTableView的结果导出为一个.csv文件

I wrote a gui program which will connect to an oracle db an retrieve data after a query is typed. the retrieved data is shown in a QTableView table model widget. and later the result of the QTableView is exported to a .csv file

QString MyQuery = ui->lineQuery->text();
db.open();
QSqlQuery query(MyQuery,db);

if(query.exec())
{
    qDebug()<<QDateTime::currentDateTime()<<"QUERY SUCCESS ";
    ui->queryButton->setStyleSheet("QPushButton {background-color: rgb(0, 255, 0);}");

    this->model=new QSqlQueryModel();
    model->setQuery(MyQuery);
    ui->tableViewOra->setModel(model);

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

    for (int i = 0; i < rows; i++)
    {
        for (int j = 0; j < columns; j++)
        {
            textData += model->data(model->index(i,j)).toString();
            textData += ", ";      // for .csv file format
        }
        textData += "\n";             // (optional: for new line segmentation)
    }

    QFile csvfile("/home/aj/ora_exported.csv");
    if(csvfile.open(QIODevice::WriteOnly|QIODevice::Truncate))
    {
        QTextStream out(&csvfile);
        out<<textData;
    }
    csvfile.close();
}

现在的问题是,在查询过程中我发现有543行可见QTableView(这是正确的原因有543条目)。但是当导出.csv文件时,只有256行。

now the problem is, during a query I observed there are 543 rows visible in the QTableView (which is correct cause there are 543 entries). But when the .csv file is exported, only 256 rows are there.

是否有任何变数大小限制,我不知道???

Is there any variable size constraint that I am unaware about ???

如果我想导出.csv文件的高达1000行约???感谢。

Which variables should be taken care of if I want to export .csv files of upto 1000 rows approx ??? thanks.

推荐答案

我想当你第一次阅读 model-> rowCount $ c>模型尚未完全获取所有结果。虽然在显示表视图时会提取更多,从而在表视图中显示完整的行。

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.

尝试使用 QSqlQueryModel :: fetchMore 之前读取行计数:

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

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

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






[Tay2510的更多信息]:


[Additional information from Tay2510]:

您可以更改文件打开标志

You could just change the file open flag

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

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


b $ b

前者将覆盖同一文件,而后者附加数据。

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

这篇关于QTableView导出到.csv获取的行数限制为仅256的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆