Solved Mainwindow and Second window closes after saving QTableWidget contents in .csv file.
-
Hi all,
This is my first question here, hope to get get answer soon.
I have processed some data and displayed it on QTableWidget on second window.
I used Qtetxstream and QFile to save this data in .csv file using pushbutton.
But as soon as I click Pushbutton though the contents are saved, it closes both MainWindow and Second window and show message as The program has unexpectedly finished.Code snippet:
void ErrorInfoTable::on_pushButton_Save_clicked()
{
QFile file(file path);if(!file.open(QFile::WriteOnly | QFile::Truncate)) { QMessageBox::warning(this, "", "File not open"); }
for(int row = 0; row < NumberofErrors_ErrInfo; row++)
{
for(int col = 0; col < 6; col++)
{
QTextStream out(&file);
QString text = ui->tableWidget->item(row, col)->text();
out << text << ",";
file.flush();
if(col == 5)
{
out << "\n";
}
}}
file.close();
}
-
Debug and try to find the line where exactly the crash happens
-
hi @Rututraj
said in Mainwindow and Second window closes after saving QTableWidget contents in .csv file.:QString text = ui->tableWidget->item(row, col)->text();
best guess is, either row or col is to large, for the tableWidget index
-
@J-Hilk
Yes row index was getting out of range,
Thanks :)