Skip to content

Commit

Permalink
Export: use QSaveFile to get better error check on full partition
Browse files Browse the repository at this point in the history
Note that, at least under Linux, this will still fail to detect the
error due to this Qt bug: https://bugreports.qt.io/browse/QTBUG-75077

See issue sqlitebrowser#3243
  • Loading branch information
mgrojo committed Dec 27, 2022
1 parent ce176be commit 496d39d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/ExportDataDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "IconCache.h"
#include "Data.h"

#include <QFile>
#include <QSaveFile>
#include <QTextStream>
#include <QMessageBox>
#include <QTextCodec>
Expand Down Expand Up @@ -109,7 +109,7 @@ bool ExportDataDialog::exportQueryCsv(const std::string& sQuery, const QString&
std::string special_chars = newlineStr.toStdString() + sepChar.toLatin1() + quoteChar.toLatin1();
bool writeError = false;
// Open file
QFile file(sFilename);
QSaveFile file(sFilename);
if(file.open(QIODevice::WriteOnly))
{
// Open text stream to the file
Expand Down Expand Up @@ -186,7 +186,9 @@ bool ExportDataDialog::exportQueryCsv(const std::string& sQuery, const QString&
qApp->processEvents();

// Done writing the file
file.close();
if(!file.commit()) {
writeError = true;
}

if(writeError || file.error() != QFileDevice::NoError) {
QMessageBox::warning(this, QApplication::applicationName(),
Expand All @@ -207,7 +209,7 @@ bool ExportDataDialog::exportQueryCsv(const std::string& sQuery, const QString&
bool ExportDataDialog::exportQueryJson(const std::string& sQuery, const QString& sFilename)
{
// Open file
QFile file(sFilename);
QSaveFile file(sFilename);
if(file.open(QIODevice::WriteOnly))
{
auto pDb = pdb.get(tr("exporting JSON"));
Expand Down Expand Up @@ -289,7 +291,9 @@ bool ExportDataDialog::exportQueryJson(const std::string& sQuery, const QString&
qApp->processEvents();

// Done writing the file
file.close();
if(!file.commit()) {
writeError = true;
}

if(writeError || file.error() != QFileDevice::NoError) {
QMessageBox::warning(this, QApplication::applicationName(),
Expand Down

0 comments on commit 496d39d

Please sign in to comment.