From 6d1b4cfa61b72750c26ab285f60cc95b70ead9f0 Mon Sep 17 00:00:00 2001 From: Dieter Mayer Date: Mon, 27 Jul 2026 10:14:17 +0200 Subject: [PATCH] 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) --- sources/qetproject.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/sources/qetproject.cpp b/sources/qetproject.cpp index ca8a64cd3..cf7dfc799 100644 --- a/sources/qetproject.cpp +++ b/sources/qetproject.cpp @@ -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); + }); } /**