Repository navigation
fix: prevent palette feedback binding loops - #729
Conversation
1. Store palette changed connection and disconnect it when control changes to avoid stale connections 2. Add null check for palette pointer before connecting to changed signal 3. Defer updateControlTheme via scheduleControlThemeUpdate using queued connection to break binding feedback loops 4. Add m_controlThemeUpdatePending flag to coalesce multiple update requests 5. Add unit tests for deferred/coalesced palette updates, destruction with pending updates, and styled control palette feedback The palette is both an input and output of the color selector, causing binding loops when palette changes triggered immediate writes back to the same palette. Deferring the update to the next event loop iteration allows existing bindings to finish before notifying again. The connection cleanup prevents dangling connections when the control's palette changes. Influence: 1. Test controls with palette bindings to D.ColorSelector (Button, ToolButton, MenuItem) 2. Verify no "Binding loop" warnings appear in console 3. Test theme switching between light and dark modes 4. Test hover, press, checked, disabled states with palette feedback 5. Verify selector destruction while a palette update is pending does not crash 6. Confirm palette updates settle and do not trigger continuous event processing fix: 修复调色板反馈导致的绑定循环 1. 保存调色板 changed 信号连接,在控件切换时断开以避免遗留连接 2. 连接 changed 信号前增加调色板空指针检查 3. 通过 scheduleControlThemeUpdate 使用队列连接延迟 updateControlTheme 以打破绑定反馈循环 4. 添加 m_controlThemeUpdatePending 标志合并多次更新请求 5. 添加延迟/合并调色板更新、销毁时存在待处理更新、以及带样式控件调色板反 馈的单元测试 调色板既是颜色选择器的输入也是输出,当调色板变化立即回写同一调色板时会触 发绑定循环。将更新延迟到下一个事件循环迭代,使已有绑定先完成再通知。连接 清理可避免控件调色板变化时产生悬空连接。 Influence: 1. 测试使用 D.ColorSelector 调色板绑定的控件(Button、ToolButton、 MenuItem) 2. 验证控制台不出现"Binding loop"警告 3. 测试明暗主题切换 4. 测试 hover、按下、选中、禁用状态下的调色板反馈 5. 验证存在待处理调色板更新时销毁选择器不会崩溃 6. 确认调色板更新能稳定下来,不会触发持续的事件处理
Reviewer's GuideThe selector now safely manages palette signal connections and defers/coalesces control theme updates through the event loop, breaking palette input/output binding loops while preserving stable palette synchronization; new tests cover lifecycle safety, feedback stabilization, and styled-control states. Sequence diagram for deferred palette theme updatessequenceDiagram
participant Palette as QQuickPalette
participant Selector as DQuickControlColorSelector
participant EventLoop
participant Binding
Palette->>Selector: scheduleControlThemeUpdate()
Selector->>Selector: Check m_controlThemeUpdatePending
Selector->>EventLoop: invokeMethod(..., Qt::QueuedConnection)
EventLoop-->>Selector: Run queued callback
Selector->>Selector: updateControlTheme()
Selector->>Binding: Notify synchronized palette colors
Binding-->>Palette: Complete existing binding
State diagram for coalesced control theme updatesstateDiagram-v2
[*] --> Idle
Idle --> UpdatePending: scheduleControlThemeUpdate()
UpdatePending --> UpdatePending: scheduleControlThemeUpdate() ignored
UpdatePending --> Idle: Queued callback calls updateControlTheme()
Idle --> [*]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: [] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: [] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: [] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: [] 💡 改进建议代码示例// 当前代码已为最佳实践,无需额外修复。 // scheduleControlThemeUpdate() 的延迟合并模式是处理 Qt 绑定循环的标准方案: // // void DQuickControlColorSelector::scheduleControlThemeUpdate() // { // if (m_controlThemeUpdatePending) // return; // m_controlThemeUpdatePending = true; // QMetaObject::invokeMethod(this, [this] { // m_controlThemeUpdatePending = false; // updateControlTheme(); // }, Qt::QueuedConnection); // }本报告由 AI 代码审查工具自动生成 |
|
LD_LIBRARY_PATH=/home/work/dtkwidget/build6/src:/home/work/dtkdeclarative/build6/qt6/src QML_IMPORT_PATH=/home/work/dtkdeclarative/build6/plugins timeout 55s gdb -q -batch -ex 'set debuginfod enabled off' -ex 'set breakpoint pending on' -ex 'break QQmlBinding::printBindingLoopError' -ex run -ex 'bt 55' --args ./build6/examples/exhibition/dtk6-exhibition 2>&1 | tail -85 Button.qml:27 (qt6/src/qml/Button.qml:27) 中: palette.windowText: D.ColorSelector.textColor 实际报警调用链为: 绑定计算完成,写入 palette.windowText 关键在 updateControlTheme() (src/private/dquickcontrolpalette.cpp:1017):即使主题没变,也会立即刷新全部颜色。本次调用栈明确经过这个分支。Qt 已对动态属性做同值判断,因此再加一次“颜色相等就返回”不能解决这次问题。 此外,setControl() (src/private/dquickcontrolpalette.cpp:470) 在 Qt 6 下同时监听 QQuickPalette::changed 和控件的 paletteChanged,存在重复刷新路径。Button、ToolButton、MenuItem 等共用该机制,所以会集中出现类似警告。 实现
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, BLumia The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
changes to avoid stale connections
signal
connection to break binding feedback loops
requests
with pending updates, and styled control palette feedback
The palette is both an input and output of the color selector, causing
binding loops when palette changes triggered immediate writes back
to the same palette. Deferring the update to the next event loop
iteration allows existing bindings to finish before notifying again.
The connection cleanup prevents dangling connections when the control's
palette changes.
Influence:
ToolButton, MenuItem)
not crash
processing
fix: 修复调色板反馈导致的绑定循环
以打破绑定反馈循环
馈的单元测试
调色板既是颜色选择器的输入也是输出,当调色板变化立即回写同一调色板时会触
发绑定循环。将更新延迟到下一个事件循环迭代,使已有绑定先完成再通知。连接
清理可避免控件调色板变化时产生悬空连接。
Influence:
MenuItem)
Summary by Sourcery
Prevent palette feedback binding loops by safely managing palette connections and deferring coalesced control theme updates.
Bug Fixes:
Enhancements:
Tests: