@@ -107,7 +107,7 @@ bool ExportDataDialog::exportQueryCsv(const std::string& sQuery, const QString&
107107
108108 // Chars that require escaping
109109 std::string special_chars = newlineStr.toStdString () + sepChar.toLatin1 () + quoteChar.toLatin1 ();
110-
110+ bool writeError = false ;
111111 // Open file
112112 QFile file (sFilename );
113113 if (file.open (QIODevice::WriteOnly))
@@ -144,7 +144,7 @@ bool ExportDataDialog::exportQueryCsv(const std::string& sQuery, const QString&
144144 QApplication::setOverrideCursor (Qt::WaitCursor);
145145 int columns = sqlite3_column_count (stmt);
146146 size_t counter = 0 ;
147- while (sqlite3_step (stmt) == SQLITE_ROW)
147+ while (!writeError && sqlite3_step (stmt) == SQLITE_ROW)
148148 {
149149 for (int i = 0 ; i < columns; ++i)
150150 {
@@ -178,6 +178,7 @@ bool ExportDataDialog::exportQueryCsv(const std::string& sQuery, const QString&
178178 qApp->processEvents ();
179179 counter++;
180180 }
181+ writeError = stream.status () != QTextStream::Ok;
181182 }
182183 sqlite3_finalize (stmt);
183184
@@ -186,6 +187,14 @@ bool ExportDataDialog::exportQueryCsv(const std::string& sQuery, const QString&
186187
187188 // Done writing the file
188189 file.close ();
190+
191+ if (writeError || file.error () != QFileDevice::NoError) {
192+ QMessageBox::warning (this , QApplication::applicationName (),
193+ tr (" Error while writing the file '%1': %2" )
194+ .arg (sFilename , file.errorString ()));
195+ return false ;
196+ }
197+
189198 } else {
190199 QMessageBox::warning (this , QApplication::applicationName (),
191200 tr (" Could not open output file: %1" ).arg (sFilename ));
@@ -280,6 +289,14 @@ bool ExportDataDialog::exportQueryJson(const std::string& sQuery, const QString&
280289
281290 // Done writing the file
282291 file.close ();
292+
293+ if (file.error () != QFileDevice::NoError) {
294+ QMessageBox::warning (this , QApplication::applicationName (),
295+ tr (" Error while writing the file '%1': %2" )
296+ .arg (sFilename , file.errorString ()));
297+ return false ;
298+ }
299+
283300 } else {
284301 QMessageBox::warning (this , QApplication::applicationName (),
285302 tr (" Could not open output file: %1" ).arg (sFilename ));
0 commit comments