Skip to content

Commit 32ad35f

Browse files
committed
#3578 fix: possible crash while automatic color scheme switching
Signed-off-by: Patrizio Bekerle <[email protected]>
1 parent 66763c4 commit 32ad35f

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# QOwnNotes Changelog
22

3+
## 26.4.23
4+
5+
- Fixed a possible crash that occurred when Qt's internal style machinery was still
6+
processing a system color scheme change event while `applyDarkModeSettings()`
7+
was called synchronously, causing a SIGSEGV in QtWidgets; the UI update is now
8+
deferred via `QTimer::singleShot` so it runs after the current event is fully
9+
processed (for [#3578](https://github.com/pbek/QOwnNotes/issues/3578))
10+
311
## 26.4.22
412

513
- The **Shortcuts** settings action name tree now shows the full menu hierarchy,

src/utils/gui.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include <QStyleFactory>
4040
#include <QTextBlock>
4141
#include <QTextCursor>
42+
#include <QTimer>
4243
#include <QTreeWidget>
4344
#include <QTreeWidgetItem>
4445
#include <QVBoxLayout>
@@ -67,7 +68,12 @@ bool promptForColorSchemeChange(const QString &title, const QString &text,
6768
Utils::Misc::switchToLightMode();
6869
}
6970

70-
Utils::Gui::applyDarkModeSettings();
71+
// Defer the UI update so it runs after the current color scheme change event
72+
// has been fully processed by Qt's style machinery. Calling applyDarkModeSettings()
73+
// synchronously here can cause a crash (SIGSEGV at a near-null address in QtWidgets)
74+
// because qApp->setStyleSheet() is invoked while Qt's internal style update is still
75+
// on the call stack (see issue #3578).
76+
QTimer::singleShot(0, qApp, [] { Utils::Gui::applyDarkModeSettings(); });
7177
return true;
7278
}
7379

0 commit comments

Comments
 (0)