Restore crash-recovery autosave on Qt6

QETProject::writeBackup() was Qt5-only: the Qt6 branch of the guard was
an empty placeholder, so on Qt6 no backup was ever written - a silent
data-loss risk (a crash loses everything since the last manual save),
found by ispyisail in qelectrotech#553.

The Qt5-style QtConcurrent::run(function, reference-args) call did not
survive the Qt6 API change; a lambda capturing the (implicitly shared)
document copy behaves identically on both, so the version guard goes
away entirely.

Verified at runtime on the Qt6/Windows build: opening a project creates
the autosave triple (.qetautosave + .lock + .path) with valid XML
content, and a clean exit removes it again. The CLI keeps backups
disabled via setBackupEnabled(false), unchanged.

(cherry picked from commit 0f65ae8c4b2782fbfe97111bc8b369cc105ec592)
This commit is contained in:
Dieter Mayer
2026-07-27 10:14:17 +02:00
parent 66129fd15c
commit 6d1b4cfa61
+6 -10
View File
@@ -1914,21 +1914,17 @@ void QETProject::writeBackup()
{
if (!m_backup_enabled)
return;
# if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // ### Qt 6: remove
//Don't launch a new backup while the previous one is still writing:
//both would write through &m_backup_file on different threads.
if (m_backup_future.isRunning())
return;
//Capture the document by value (implicitly shared, so cheap): the
//Qt5-style QtConcurrent::run(function, reference-args) call did not
//survive the Qt6 API change, a lambda behaves identically on both.
QDomDocument xml_project(toXml());
m_backup_future = QtConcurrent::run(
QET::writeToFile,xml_project,&m_backup_file,nullptr);
# else
# if TODO_LIST
# pragma message("@TODO remove code for QT 6 or later")
# endif
qDebug() << "Help code for QT 6 or later"
<< "QtConcurrent::run its backwards now...function, object, args";
# endif
m_backup_future = QtConcurrent::run([this, xml_project]() mutable {
return QET::writeToFile(xml_project, &m_backup_file, nullptr);
});
}
/**