Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. required properties and delegates
Forum Updated to NodeBB v4.3 + New Features

required properties and delegates

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 517 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bob64
    wrote on last edited by Bob64
    #1

    Having recently upgraded to 5.15 I was working on an existing delegate and decided to tighten up the implementation by adding required to some of the custom properties in the delegate component. In the one and only place that the delegate component is used, these properties were already being assigned so this was a protection against future changes more than anything else. I did not consider this to be a significant change and I made it alongside various other changes that I believed to be more significant.

    MyDelegate.qml:

    Item {
        required property real labelHeight
        required property ...
        required property ...
        ...
    }
    

    MyListView.qml:

    ListView {
        ...
        delegate: MyDelegate {
            labelHeight: 30
            ... other required properties also set ...
        }
    }
    

    When I ran my code the list view that the delegate relates to was showing as empty. On the console I saw lots of messages that suggested that the named roles from my model were not defined: "ReferenceError: <role name> is not defined".

    After spending some time gradually backing out my changes, I finally alighted on it being caused by the required constraints I had added to the delegate. I only needed one such constraint to cause the issue. It didn't seem to matter which of the properties it was applied to.

    Are there some weird rules about when required should be used? Is it not appropriate in delegates for some reason?

    Edit: I guess the thing I found really odd about this is that I did not see any errors about the required properties, but it seemed to stop my model from being accessed in the delegate!

    Marko StankeM 1 Reply Last reply
    0
    • B Bob64

      Having recently upgraded to 5.15 I was working on an existing delegate and decided to tighten up the implementation by adding required to some of the custom properties in the delegate component. In the one and only place that the delegate component is used, these properties were already being assigned so this was a protection against future changes more than anything else. I did not consider this to be a significant change and I made it alongside various other changes that I believed to be more significant.

      MyDelegate.qml:

      Item {
          required property real labelHeight
          required property ...
          required property ...
          ...
      }
      

      MyListView.qml:

      ListView {
          ...
          delegate: MyDelegate {
              labelHeight: 30
              ... other required properties also set ...
          }
      }
      

      When I ran my code the list view that the delegate relates to was showing as empty. On the console I saw lots of messages that suggested that the named roles from my model were not defined: "ReferenceError: <role name> is not defined".

      After spending some time gradually backing out my changes, I finally alighted on it being caused by the required constraints I had added to the delegate. I only needed one such constraint to cause the issue. It didn't seem to matter which of the properties it was applied to.

      Are there some weird rules about when required should be used? Is it not appropriate in delegates for some reason?

      Edit: I guess the thing I found really odd about this is that I did not see any errors about the required properties, but it seemed to stop my model from being accessed in the delegate!

      Marko StankeM Offline
      Marko StankeM Offline
      Marko Stanke
      wrote on last edited by
      #2

      @Bob64
      I'm not sure if there is a written explanation for this.
      But yes, you are right. If you use "required" on one property (doesn't matter which one). You will need to set "required" to all properties that are coming from your model in order to access them.

      Really weird behavior, but that's how it is on Qt5 and Qt6.

      B 1 Reply Last reply
      1
      • Marko StankeM Marko Stanke

        @Bob64
        I'm not sure if there is a written explanation for this.
        But yes, you are right. If you use "required" on one property (doesn't matter which one). You will need to set "required" to all properties that are coming from your model in order to access them.

        Really weird behavior, but that's how it is on Qt5 and Qt6.

        B Offline
        B Offline
        Bob64
        wrote on last edited by
        #3

        @Marko-Stanke thanks - it sounds like there are indeed some "rules" around this. In my case, the required properties weren't even coming from the model, they were justparametrizing some aspects of the delegate.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved