From 2951658a49a1ef82da81417351e4409184833688 Mon Sep 17 00:00:00 2001 From: Antoine C Date: Sun, 15 Sep 2024 16:05:22 +0100 Subject: [PATCH 1/2] fix: prevent crash when no app windows have the focus --- src/library/librarycontrol.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/library/librarycontrol.cpp b/src/library/librarycontrol.cpp index 3d5e9cac1fa..b118117f0cb 100644 --- a/src/library/librarycontrol.cpp +++ b/src/library/librarycontrol.cpp @@ -1039,8 +1039,11 @@ void LibraryControl::slotGoToItem(double v) { // press & release Space (QAbstractButton::clicked() is emitted on release) QKeyEvent pressSpace = QKeyEvent{QEvent::KeyPress, Qt::Key_Space, Qt::NoModifier}; QKeyEvent releaseSpace = QKeyEvent{QEvent::KeyRelease, Qt::Key_Space, Qt::NoModifier}; - QApplication::sendEvent(QApplication::focusWindow(), &pressSpace); - QApplication::sendEvent(QApplication::focusWindow(), &releaseSpace); + auto window = QApplication::focusWindow(); + if (window) { + QApplication::sendEvent(window, &pressSpace); + QApplication::sendEvent(window, &releaseSpace); + } return; } case FocusWidget::ContextMenu: @@ -1054,7 +1057,10 @@ void LibraryControl::slotGoToItem(double v) { // If Unknown is some other 'untrained' or unresponsive widget // GoToItem is inappropriate and we can't do much about that. QKeyEvent event = QKeyEvent{QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier}; - QApplication::sendEvent(QApplication::focusWindow(), &event); + auto window = QApplication::focusWindow(); + if (window) { + QApplication::sendEvent(window, &event); + } return; } case FocusWidget::Searchbar: From bd4b989a6ab25a645bf09ba667d4bcaf6c4c6fb3 Mon Sep 17 00:00:00 2001 From: Antoine C Date: Mon, 16 Sep 2024 02:11:00 +0100 Subject: [PATCH 2/2] Add missing ptr marker and prefix --- src/library/librarycontrol.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/library/librarycontrol.cpp b/src/library/librarycontrol.cpp index b118117f0cb..f52cc255b7d 100644 --- a/src/library/librarycontrol.cpp +++ b/src/library/librarycontrol.cpp @@ -1039,10 +1039,10 @@ void LibraryControl::slotGoToItem(double v) { // press & release Space (QAbstractButton::clicked() is emitted on release) QKeyEvent pressSpace = QKeyEvent{QEvent::KeyPress, Qt::Key_Space, Qt::NoModifier}; QKeyEvent releaseSpace = QKeyEvent{QEvent::KeyRelease, Qt::Key_Space, Qt::NoModifier}; - auto window = QApplication::focusWindow(); - if (window) { - QApplication::sendEvent(window, &pressSpace); - QApplication::sendEvent(window, &releaseSpace); + auto* pWindow = QApplication::focusWindow(); + if (pWindow) { + QApplication::sendEvent(pWindow, &pressSpace); + QApplication::sendEvent(pWindow, &releaseSpace); } return; } @@ -1057,9 +1057,9 @@ void LibraryControl::slotGoToItem(double v) { // If Unknown is some other 'untrained' or unresponsive widget // GoToItem is inappropriate and we can't do much about that. QKeyEvent event = QKeyEvent{QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier}; - auto window = QApplication::focusWindow(); - if (window) { - QApplication::sendEvent(window, &event); + auto* pWindow = QApplication::focusWindow(); + if (pWindow) { + QApplication::sendEvent(pWindow, &event); } return; }