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();
}
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 ???
Which variables should be taken care of if I want to export .csv files of upto 1000 rows approx ??? thanks.
qDebug()
is your good friend. – CharpoyQSqlQueryModel::fetchMore
and see if it helps. – PoltrooneryqDebug()
to check 1. ifrows
got from model really equal to 543 2. if the loop for writing files really processed and write EXACTLY 543 rows. Besides, it could also be a problem that successive calls ofquery.exec()
render the program unable to finish writing files in time. – Charpoy