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

Give a warning if the parent property of a QObject is accessed in QML

    XMLWordPrintable

Details

    • All

    Description

      I exported a data structure to QML by creating a QObject with properties and then registering it using qmlRegisterType<..>(..). Then I tried to set some properties using the parent object:

      MyPane { // Custom Pane, property is set where the component is used.
        property int entityId
        MyEntity { // Exported QObject
          // This does not work! I get an undef is assigned to int warning, but
          // that's it.
          entityId: parent.entityId
        }
      }

      I solved the issue by giving the parent an id and then refer through this in the child QObject. Now of course this is not a defect in QML but very confusing for QML devs (and I wasted some time figuring this out). I propose two things:

      • At least give a warning if the parent property is accessed from a non- QQuickItem or do not compile at all.
      • More convenient: Make parent work somehow all the time in QML. I do not see a use case where the parent property should not refer to the parent.

      Attachments

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

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            pingu Nils Brünggel
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes