]> cloud.milkyroute.net Git - dolphin.git/commitdiff
generalviewsettingspage: Use qobject_cast instead of static_cast
authorAkseli Lahtinen <akselmo@akselmo.dev>
Wed, 13 Nov 2024 09:41:45 +0000 (11:41 +0200)
committerAkseli Lahtinen <akselmo@akselmo.dev>
Wed, 13 Nov 2024 09:42:25 +0000 (09:42 +0000)
In generalViewSettingsPage, ActiveWindow is not necessarily a
mainWindow, which can cause dolphin to crash. For example when user
opens folder properties and then dolphin settings, this part thinks
the folder settings is mainWindow.

Instead of static_cast, use qobject_cast, since it will return nullptr
if the DolphinMainWindow is not found.

BUG:492741

src/settings/viewmodes/generalviewsettingspage.cpp

index c518147dd65e974d4f3f2fdd399421f2dde05561..00bbae29648017d64effda1cea3ad5d78407ff4a 100644 (file)
@@ -126,7 +126,8 @@ GeneralViewSettingsPage::GeneralViewSettingsPage(const QUrl &url, QWidget *paren
     m_doubleClickViewComboBox->addItem(QIcon::fromTheme("list-add"), i18nc("@item:inlistbox", "Custom Command"), customCommand);
     m_doubleClickViewComboBox->insertSeparator(2);
 
     m_doubleClickViewComboBox->addItem(QIcon::fromTheme("list-add"), i18nc("@item:inlistbox", "Custom Command"), customCommand);
     m_doubleClickViewComboBox->insertSeparator(2);
 
-    DolphinMainWindow *mainWindow = static_cast<DolphinMainWindow *>(QApplication::activeWindow());
+    DolphinMainWindow *mainWindow = qobject_cast<DolphinMainWindow *>(QApplication::activeWindow());
+
     if (mainWindow != nullptr) {
         KActionCollection *actions = mainWindow->actionCollection();
         // get the allowed actions from actionCollection and add them to the combobox
     if (mainWindow != nullptr) {
         KActionCollection *actions = mainWindow->actionCollection();
         // get the allowed actions from actionCollection and add them to the combobox