Skip to content

fix: remove dead _disconnect hooks on QModelMenu/QModelToolBar - #291

Merged
tlambert03 merged 1 commit into
pyapp-kit:mainfrom
tlambert03:fix/qt-dead-disconnect
Nov 20, 2026
Merged

tlambert03 merged 1 commit into
pyapp-kit:mainfrom
tlambert03:fix/qt-dead-disconnect

Conversation

@tlambert03

Copy link
Copy Markdown
Member

closes #157

as described in #157, the self.destroyed.connect(self._disconnect) hookups on QModelMenu and QModelToolBar never actually get called (on PyQt6 or PySide6). It turns out we don't need them though... psygnal only holds a weak ref to _on_registry_changed, so the connection cleans itself up once the python wrapper is garbage collected. So this just removes the dead code.

The one case that can still bite is when the C++ object has been deleted but something still holds a reference to the python wrapper (so the slot is still connected). QModelMenu already handles that by suppressing the RuntimeError in _on_registry_changed (from #151), but QModelToolBar didn't, and menus_changed.emit() would raise an EmitLoopError. This adds the same suppression to the toolbar, plus a test for both.

`destroyed.connect(self._disconnect)` never actually fires.  It isn't needed:
psygnal holds the slot weakly, so the connection goes away when the python
wrapper is collected.  Also suppress RuntimeError in
QModelToolBar._on_registry_changed (as QModelMenu already does), for the case
where the C++ object is deleted but the wrapper is still alive.

closes pyapp-kit#157
@codecov

codecov Bot commented Nov 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.49%. Comparing base (684092d) to head (8908165).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #291      +/-   ##
==========================================
- Coverage   99.49%   99.49%   -0.01%     
==========================================
  Files          31       31              
  Lines        1975     1970       -5     
==========================================
- Hits         1965     1960       -5     
  Misses         10       10              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tlambert03
tlambert03 merged commit cbd06be into pyapp-kit:main Nov 20, 2026
42 checks passed
@tlambert03
tlambert03 deleted the fix/qt-dead-disconnect branch November 20, 2026 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Bug in _disconnect functions on QObjects

1 participant