Skip to content

Commit fd3df1f

Browse files
committed
Use QSaveFile to avoid losing the project file on abort
See https://doc.qt.io/qt-5/qsavefile.html > QSaveFile is an I/O device for writing text and binary files, without > losing existing data if the writing operation fails. See issue #3662
1 parent 73ebe93 commit fd3df1f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/MainWindow.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include <chrono>
3232
#include <QFile>
33+
#include <QSaveFile>
3334
#include <QTextStream>
3435
#include <QWhatsThis>
3536
#include <QMessageBox>
@@ -3094,7 +3095,7 @@ void MainWindow::saveProject(const QString& currentFilename)
30943095
if(!filename.endsWith(FILE_EXT_SQLPRJ_DEFAULT, Qt::CaseInsensitive))
30953096
filename.append(FILE_EXT_SQLPRJ_DEFAULT);
30963097

3097-
QFile file(filename);
3098+
QSaveFile file(filename);
30983099
bool opened = file.open(QFile::WriteOnly | QFile::Text);
30993100
if(!opened) {
31003101
QMessageBox::warning(this, qApp->applicationName(),
@@ -3227,7 +3228,7 @@ void MainWindow::saveProject(const QString& currentFilename)
32273228

32283229
xml.writeEndElement();
32293230
xml.writeEndDocument();
3230-
file.close();
3231+
file.commit();
32313232

32323233
addToRecentFilesMenu(filename);
32333234
setCurrentFile(db.currentFile());

0 commit comments

Comments
 (0)