Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-139732

Binding created with QQmlAnyBinding::createFromScriptString is not evaluated on QNX

XMLWordPrintable

      In https://codereview.qt-project.org/c/qt/qtdeclarative/+/638956 we have this code:

      void QQuickDeleteAction::componentComplete()
      {
          connect(this, &QQuickAction::triggered, [this]() {
              QQuickItem *editor = d_func()->editor;
              const int selectionStart = editor->property("selectionStart").value<int>();
              const int selectionEnd = editor->property("selectionEnd").value<int>();
              QMetaObject::invokeMethod(editor, "remove", selectionStart, selectionEnd);
          });
      
      #if !QT_CONFIG(clipboard)
          setEnabled(false);
          return;
      #endif
      
          const QString enabledPropertyName = "enabled"_L1;
          auto *ourQmlContext = qmlContext(this);
          const QQmlProperty enabledProperty(this, enabledPropertyName, ourQmlContext);
          // Only install our binding if the user hasn't set one.
          if (QQmlPropertyPrivate::binding(enabledProperty))
              return;
      
          // Bind the enabled property to the following QML expression:
          const QString expression = "editor ? !editor.readOnly && editor.selectedText.length > 0 : false"_L1;
          const QQmlScriptString scriptString = QQmlScriptStringPrivate::create(expression, ourQmlContext, this);
          auto newBinding = QQmlAnyBinding::createFromScriptString(
              enabledProperty, scriptString, this, ourQmlContext);
          newBinding.installOn(enabledProperty);
      }
      

      The resultant binding is evaluated on all platforms except QNX, leading to this failure:

      agent:2025/09/02 11:10:11 build.go:413: FAIL!  : tst_QQuickTextArea::Basic::contextMenuDelete() 'deleteMenuItem->isEnabled()' returned FALSE. (Expected deleteMenuItem to be enabled; editor.readOnly: 0 editor.selectedText: " mori")
      agent:2025/09/02 11:10:11 build.go:413:    Loc: [/home/qt/work/qt/qtdeclarative/tests/auto/quickcontrols/qquicktextarea/tst_qquicktextarea.cpp(421)]
      

      https://codereview.qt-project.org/c/qt/qtdeclarative/+/638956/62#message-ab3888395d9f0f9aad957d43a944ceddd4a04120

      In https://codereview.qt-project.org/c/qt/qtdeclarative/+/638956/62/src/quicktemplates/qquickdeleteaction.cpp#50, I added debugging code to verify this:

          const QString expression = "(() => { print('@@@ editor', editor); return editor ? !editor.readOnly && editor.selectedText.length > 0 : false })()"_L1;
      

      It doesn't show up in the output.

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            qtqmlteam Qt Qml Team User
            mitch_curtis Mitch Curtis
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes