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

Assigning attached property to Connections.target results in error

    XMLWordPrintable

Details

    • macOS, Windows
    • dbbbbe569da0aa3900a17ca22bd2be2708fb76f7 (qt/qtdeclarative/5.12)

    Description

      import QtQuick 2.10
      import QtQuick.Layouts 1.1
      
      Item {
          id: root
      
          Rectangle {
              id: rect
              width: 50
              height: 50
              color: "red"
              Layout.preferredWidth: 50
      
              MouseArea {
                  anchors.fill: parent
                  onClicked: {
                      if (rect.Layout) {
                          console.log(rect.Layout)
                          cnLayout.target = rect.Layout
                          cnLayout.target = rect.Component // The same problem.
                          // Prints:
                          // qml: QQuickLayoutAttached(0x7fd0d6e5ad20)
                          // file:///Users/uzumcuf/Desktop/QMLBug/main.qml|20| Error: Cannot assign null to QObject*
                      }
                  }
              }
          }
      
          Connections {
              id: cnLayout
              ignoreUnknownSignals: true
          }
      }
      

      The above code results in the printed error. I'm checking to see If the `rect.Layout` is `null` or not before the assignment, the log shows that the object is not null. But QML still complains that it cannot do a nuill assignment to QObject.

      I should clarify, this is not specific to Layout attached property, but to attached properties in general.

      Attachments

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

        Activity

          People

            ulherman Ulf Hermann
            furkanzmc Furkan Üzümcü
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes