From 5fff1e414a060c0619a97ad8d3f5665e3f5a4878 Mon Sep 17 00:00:00 2001 From: "Friedrich W. H. Kossebau" Date: Fri, 9 Jan 2026 16:16:48 +0100 Subject: Use Q_ASSERT instead of Q_CHECK_PTR for plain checks of pointer value Q_CHECK_PTR (other than the name suggests) is intended only to check the success of memory allocations. Using it for any pointers instead can be misleading due to the "Out of memory" log printed in case of hits. --- src/selectionmode/actiontexthelper.cpp | 2 +- src/selectionmode/actionwithwidget.cpp | 4 ++-- src/selectionmode/actionwithwidget.h | 2 +- src/selectionmode/bottombarcontentscontainer.cpp | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/selectionmode') diff --git a/src/selectionmode/actiontexthelper.cpp b/src/selectionmode/actiontexthelper.cpp index b54e9b004..1e331860a 100644 --- a/src/selectionmode/actiontexthelper.cpp +++ b/src/selectionmode/actiontexthelper.cpp @@ -16,7 +16,7 @@ ActionTextHelper::ActionTextHelper(QObject *parent) void ActionTextHelper::registerTextWhenNothingIsSelected(QAction *action, QString registeredText) { - Q_CHECK_PTR(action); + Q_ASSERT(action); m_registeredActionTextChanges.emplace_back(action, registeredText, TextWhenNothingIsSelected); } diff --git a/src/selectionmode/actionwithwidget.cpp b/src/selectionmode/actionwithwidget.cpp index cc407d334..2ab613ba2 100644 --- a/src/selectionmode/actionwithwidget.cpp +++ b/src/selectionmode/actionwithwidget.cpp @@ -28,7 +28,7 @@ ActionWithWidget::ActionWithWidget(QAction *action, QAbstractButton *button) QWidget *ActionWithWidget::newWidget(QWidget *parent) { - Q_CHECK_PTR(m_action); + Q_ASSERT(m_action); Q_ASSERT(!m_widget); if (m_action->isSeparator()) { @@ -45,7 +45,7 @@ QWidget *ActionWithWidget::newWidget(QWidget *parent) QAbstractButton *SelectionMode::newButtonForAction(QAction *action, QWidget *parent) { - Q_CHECK_PTR(action); + Q_ASSERT(action); Q_ASSERT(!action->isSeparator()); if (action->priority() == QAction::LowPriority) { diff --git a/src/selectionmode/actionwithwidget.h b/src/selectionmode/actionwithwidget.h index e56729a6f..8e09e92e0 100644 --- a/src/selectionmode/actionwithwidget.h +++ b/src/selectionmode/actionwithwidget.h @@ -44,7 +44,7 @@ public: /** @returns the action of this object. */ inline QAction *action() { - Q_CHECK_PTR(m_action); + Q_ASSERT(m_action); return m_action; }; diff --git a/src/selectionmode/bottombarcontentscontainer.cpp b/src/selectionmode/bottombarcontentscontainer.cpp index bb858b871..3f7e681dd 100644 --- a/src/selectionmode/bottombarcontentscontainer.cpp +++ b/src/selectionmode/bottombarcontentscontainer.cpp @@ -42,7 +42,7 @@ void BottomBarContentsContainer::resetContents(BottomBar::Contents contents) updateExplanatoryLabelVisibility(); }); - Q_CHECK_PTR(m_actionCollection); + Q_ASSERT(m_actionCollection); m_contents = contents; switch (contents) { case BottomBar::CopyContents: @@ -499,7 +499,7 @@ std::vector BottomBarContentsContainer::contextActionsFor(const KFile // We are going to add the actions from the right-click context menu for the selected items. auto *dolphinMainWindow = qobject_cast(window()); - Q_CHECK_PTR(dolphinMainWindow); + Q_ASSERT(dolphinMainWindow); if (!m_fileItemActions) { m_fileItemActions = new KFileItemActions(this); m_fileItemActions->setParentWidget(dolphinMainWindow); -- cgit v1.3