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

QtQuick allows declaring of and assigning to data property

    XMLWordPrintable

Details

    Description

      I ran into a hard to debug issue today, where I mistakingly declared a property called data in a custom Quick item. When testing my work, I noticed that none of the child items inside the new component would show in the scene, but the root item did.

      Investigation showed that the root issue was that QQuickItem already declares a property with this name and marks it as the default property. So, the items I created would be created as child items of the object I assigned to the data property, and not to the parent item. This was revealed by inspection with the Gamma Ray tool.

      I tried removing the offending data property, but still had the same issue. It turns out that I forgot to remove the original assignment to that property from the place where I was using the item, and even just assigning to the now not redeclared property still caused the same problem.

      Note that no warnings showed up in the output.

      I created a minimal testcase to demo the issue. The result should be a grey window with a red rectangle centered inside it. If you uncomment either of the commented out lines in main.qml or MyItem.qml (or both), you will see the red rectangle will no longer show in the scene.

      Note that the demo will create some output, but it is not directly related with the core issue.

      I looked at the code of QQmlItem, and I noticed that it is a Q_PRIVATE_PROPERTY without a setter defined. I am clueless why I can still assign to this property.

      I would expect at least a warning and preferably an error when you do this.

      Attachments

        1. MyItem.qml
          0.4 kB
          André Somers
        2. main.qml
          0.4 kB
          André Somers
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            srutledg Shawn Rutledge
            andre André Somers
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes