Skip to content

Harden m_flagTimerFilteredWindow against dangling: raw QWidget* → QPointer #3769

Description

@ten9876

Follow-up to #3764 (which landed the #3746 idle-pause work).

SpectrumWidget::m_flagTimerFilteredWindow is a raw QWidget* pointing at the watched top-level window. It's safe on today's teardown paths — prepareForTopLevelChange() detaches the event filter and nulls the pointer, and Qt auto-removes the filter when either object is destroyed — but the removeEventFilter() calls in attachFlagTimerWindowWatcher() and prepareForTopLevelChange() would be UB if a future code path ever destroyed the watched window without first routing through prepareForTopLevelChange() (the raw pointer would dangle, non-null).

Fix

Change m_flagTimerFilteredWindow to QPointer<QWidget>. A destroyed window then reads back as null, so the guarded removeEventFilter() calls become no-ops automatically — bulletproof for ~zero cost. Verify the == window() / != this comparisons and the installEventFilter/removeEventFilter sites still read correctly (QPointer converts implicitly to the raw pointer for these).

Scope

  • src/gui/SpectrumWidget.h — member type + #include <QPointer> if not already present
  • src/gui/SpectrumWidget.cpp — no logic change expected; the guarded derefs already null-check

Defensive hardening only; no behavior change. Raised in the #3764 review.

Metadata

Metadata

Assignees

No one assigned

    Labels

    GUIUser interfaceenhancementImprovement to existing featuregood first issueGood for newcomersmaintainer-reviewRequires maintainer review before any action is takenpriority: lowLow priorityspectrumPanadapter and waterfall

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions