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

Using required properties on delegates causes the firing of wrong CHANGED signal with the index being always zero

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • 6.5.3, 6.7.3, 6.8.0
    • Quick: Other
    • None
    • macOS

    Description

      This is one of the most frustrating Qt bugs I've encountered. I spent hours trying to debug what's wrong with my code.

      Here's how to reproduce it. Run the following code, and scroll. You'll notice 2 incorrect behaviors:

      1. The delegate properties CHANGED signal are being fired for no good reason (they haven't changed, they should not be called).
      2. The index of the supposed CHANGED delegates is ALWAYS 0, for all of them.

      This has caused some nasty bugs on my program. I believe I have the same issue with my previous app as well, but somehow managed to work around it temporarily.

      The issue is NOT present if I'm not using the "required" keyword, and instead using the non-recommend injected "model" to access the roles of the model.

      This issue is present even when using AbstractListModel passed from C++ (my original situation, I just managed to reproduce it using QML ListModel as well).

       

      import QtQuick
      import QtQuick.Controls
      
      Window {
          id: root
          width: 400
          height: 400
          visible: true    
          ListModel {
              id: testModel        
              Component.onCompleted: {
                  for (let i = 0; i < 100; i++) {
                      testModel.append({message: "Hello", messageRole: 1});
                  }            for (let j = 0; j < 100; j++) {
                      testModel.append({message: "Bye", messageRole: 2});
                  }
              }
          }    
          
          ListView {
              anchors.fill: parent
              model: testModel
              delegate: Text {
                  id: delegate
                  color: "black"
                  width: implicitWidth
                  height: implicitHeight
                  text: message            
                  required property int index
                  required property string message
                  required property int messageRole            
               onMessageChanged: {
                      console.log("message changed at index:", index, "messageRole:", delegate.messageRole ,"message:", message);
                  }
              }
          }
      } 

       

       

      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
            rubymamis Ruby Mamistvalove
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes