From 51597ad9fcc459edaed7bf444da1e2a1a3c41e56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E7=99=BD=E5=8F=94?= <11794527+absfan@user.noreply.gitee.com> Date: Sun, 1 Nov 2026 22:53:59 +0800 Subject: [PATCH] fix(ui): guard project plan cleanup after qt child deletion --- docs/testing/2026-11-01-dsh-pr11-review149.md | 20 +++++++++++++++++++ .../trial_task_center/ui/project_plan.py | 6 ++++++ tests/ui/test_pr10_review_edges.py | 8 ++++++++ 3 files changed, 34 insertions(+) create mode 100644 docs/testing/2026-11-01-dsh-pr11-review149.md diff --git a/docs/testing/2026-11-01-dsh-pr11-review149.md b/docs/testing/2026-11-01-dsh-pr11-review149.md new file mode 100644 index 0000000..18cd3e9 --- /dev/null +++ b/docs/testing/2026-11-01-dsh-pr11-review149.md @@ -0,0 +1,20 @@ +# PR #11 评论 #149 修复验证 + +## 根因 + +评论 #149 报告完整 UI/DSH 套件在 fixture 清理阶段访问已被 Qt 回收的 `ProjectPlanPanel.report_toggle`,错误为 `RuntimeError: Internal C++ object (QToolButton) already deleted`。相关测试单独运行会通过,问题只在完整测试顺序和窗口销毁时序下暴露。 + +## 修复 + +`ProjectPlanPanel._restore_bom_report()` 在更新报告控件前使用 `shiboken6.isValid()` 检查自身和 Qt 子控件。内存中的 BOM 预览仍照常释放;控件已经由 Qt 回收时跳过 UI 更新,避免清理路径再次调用已失效的 C++ 包装器。 + +新增回归覆盖子控件已被回收后调用 `discard_all()` 的情况;修复前稳定复现评论中的异常,修复后通过。 + +## 验证 + +- 相关 UI/生命周期回归:70 passed。 +- 完整套件:**1819 passed,1 skipped,1 warning,0 error**。 +- 跳过项为本机缺少 DxDesigner 7.9.5 生成 type library;警告为 pywinauto 的预期 COM 线程模式提示。 +- Python 编译、JS 语法和 `git diff --check` 通过。 + +未修改 PR #10 分支,未操作真实 CAD、远端工单或冻结 EXE。 diff --git a/src/dx_productivity/trial_task_center/ui/project_plan.py b/src/dx_productivity/trial_task_center/ui/project_plan.py index 47be139..05ff0b0 100644 --- a/src/dx_productivity/trial_task_center/ui/project_plan.py +++ b/src/dx_productivity/trial_task_center/ui/project_plan.py @@ -10,6 +10,7 @@ from PySide6.QtGui import QAction,QKeySequence from PySide6.QtWidgets import (QDialog, QDialogButtonBox, QFileDialog, QHBoxLayout, QLabel, QLineEdit, QListWidget, QListWidgetItem, QMessageBox, QPushButton, QVBoxLayout, QWidget, QToolButton, QMenu) +from shiboken6 import isValid from .detail_windows import BomReportDialog from .target_table import TargetTable @@ -669,6 +670,11 @@ class ProjectPlanPanel(QWidget): self.report_toggle.setChecked(False) def _restore_bom_report(self, scope): + # Qt may reclaim an owned control while the parent window is already + # closing. Cleanup still needs to release the in-memory preview, but + # must not call into a dead C++ wrapper. + if not isValid(self) or not isValid(self.report_toggle): + return machine = self._bom_imports.get(scope) state = machine.state if machine is not None else BomImportState() self.last_bom_report = state.report diff --git a/tests/ui/test_pr10_review_edges.py b/tests/ui/test_pr10_review_edges.py index a8f411e..1d6e0ad 100644 --- a/tests/ui/test_pr10_review_edges.py +++ b/tests/ui/test_pr10_review_edges.py @@ -10,6 +10,14 @@ from PySide6.QtCore import Signal from PySide6.QtWidgets import QMessageBox,QWidget +def test_project_plan_discard_is_safe_after_qt_reclaims_report_control(ui, qtbot): + """Fixture cleanup must tolerate a child control reclaimed during window teardown.""" + import shiboken6 + report_toggle = ui.window.plan_panel.report_toggle + shiboken6.delete(report_toggle) + ui.window.plan_panel.discard_all() + + @pytest.mark.parametrize('scope',['single','batch']) @pytest.mark.parametrize('stop_kind',['none','pause','force','pause_then_reauthorize']) def test_last_failed_item_keeps_stop_intent_in_automatic_diagnosis(ui,qtbot,monkeypatch,scope,stop_kind):