Skip to content

Fix the shortcuts dialog's implicitWidth binding loop - #72

Open
greenermoose wants to merge 1 commit into
omacom:masterfrom
greenermoose:fix-shortcuts-dialog-binding-loop
Open

greenermoose wants to merge 1 commit into
omacom:masterfrom
greenermoose:fix-shortcuts-dialog-binding-loop

Conversation

@greenermoose

Copy link
Copy Markdown

Every launch of Omawrite 0.5.0 logs this four times, before any dialog is opened:

qrc:/Main.qml:327:5: QML Dialog: Binding loop detected for property "implicitWidth":
qrc:/qt-project.org/imports/QtQuick/Controls/Material/Dialog.qml:14:5

It comes from the Ctrl+? "Keyboard shortcuts" Dialog, which assigns a bare Label as its contentItem. Material's Dialog.qml derives implicitWidth from the content item's implicit width, and with a custom content item that value feeds back into the popup's own sizing while the binding is still being evaluated, so QML flags a loop. The dialog still renders and sizes correctly, which is why it is easy to miss — and Qt routes the message to journald rather than stderr whenever stderr is not a TTY, so piping the output looks clean.

Fix: declare the Label as a child of the Dialog instead, so the default content item owns the sizing. Measured offscreen with Qt 6.11.2, the dialog's implicit size is identical (269.6 × 456) and the warnings drop from 2 to 0. Wrapping the label in a Column while keeping contentItem: does not help; the loop is in the custom-content-item path itself. The objectName exists only so the test can find the dialog.

Test: shortcutsDialogHasNoBindingLoop loads Main.qml, opens the dialog, and fails on any "Binding loop detected" message. It fails against the current dialog (2 loops) and passes with this change; the full suite is 13/13.

Reproduce on 0.5.0:

QT_FORCE_STDERR_LOGGING=1 QT_QPA_PLATFORM=offscreen timeout -s TERM 4 omawrite some.md 2>&1 | grep -c 'Binding loop'
# 4 before, 0 after

🤖 Generated with Claude Code

Every launch logged, four times before any dialog was opened:

  qrc:/Main.qml:327:5: QML Dialog: Binding loop detected for property
  "implicitWidth": .../QtQuick/Controls/Material/Dialog.qml:14:5

The Ctrl+? shortcuts Dialog assigns a bare Label as its contentItem.
Material's Dialog derives implicitWidth from the content item's implicit
width, and with a custom content item that value feeds back into the
popup's own sizing while the binding is still being evaluated, so QML
flags a loop. The dialog rendered correctly regardless, and Qt routes
the message to journald rather than stderr when stderr is not a TTY,
which is why it was easy to miss.

Declare the Label as a child instead, so the default content item owns
the sizing. Measured offscreen with Qt 6.11.2 the dialog's implicit size
is unchanged (269.6 x 456) and the warnings drop from 2 to 0; wrapping
the label in a Column while keeping contentItem does not help, the loop
is in the custom-content-item path itself.

The new test loads Main.qml, opens the dialog and fails on any "Binding
loop detected" message: it fails against the old dialog (2 loops) and
passes with this change.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant