Repeater bug?



  • Hello I have the following basic code:
    @import QtQuick 2.0
    import QtGraphicalEffects 1.0

    Item {
    id: idRoot
    width:800
    height:480

    property real nbrOfOccurences: 10
    
    Item {
        id: idItem1
        Repeater {
            id: idImagesRepeater
            model: nbrOfOccurences
            Image {
                id: idImage
                source: "someimage.png"
                x: Math.ceil(Math.random() * 650) 
                y: Math.ceil(Math.random() * 350) 
                visible: true
            }
    
        }
    
        Repeater {
            model: nbrOfOccurences
            ColorOverlay {
                source: idItem1.children[index]
                anchors.fill: idItem1.children[index]
                color: Qt.rgba(Math.random(),Math.random(),Math.random())
                visible: true
               
            }
    
        }
        visible: true
    
    }
    

    }
    @

    -> i know that source image shall be set to false, I set them to true intentionally.
    -> running this code, I see 9 images on which a ColorOverlay is applied, and the first image does not have the ColorOverlay effect applied. Anyone can spot my error, or is it a repeater error?



  • The following code seems to be OK, But I still want to understand what is wrong with the original proposition in the first post?
    And yes, I know that source image shall be set to false, I set them to true intentionally.

    @ import QtQuick 2.0
    import QtGraphicalEffects 1.0

    Item {
        id: idRoot
        width:800
        height:480
     
        property real nbrOfOccurences: 10
     
    
            Repeater {
                id: idImagesRepeater
                model: nbrOfOccurences
                        Item {
                                    id: idItem1
    
                                      Image {
                                            id: idImage
                                            source: "someimage.png"
                                            x: Math.ceil(Math.random() * 650)
                                            y: Math.ceil(Math.random() * 350)
                                            visible: true
                                        }
                                    
                                        ColorOverlay {
                                            source: idImage
                                            anchors.fill: idImage
                                            color: Qt.rgba(Math.random(),Math.random(),Math.random())
                                            visible: true
                                        }
                        visible: true
     
                      }
            }
     
    }
    

    @


  • Moderators

    Hi,

    I guess that would be because the idItem1's first child would be a Repeater. Your second approach is actually the right way to do it.



  • Hello,
    actually I printed out the children and the images are the first children indeed, the repeater is coming after the images in the children list.
    The first proposal works fine for the 9 following images, it only fails for the first one. I still would like to understand why? Is there a Qt bug or not?

    Bill


  • Moderators

    Try printing it in ColorOverlay since at that point only the First Repeaters Items are popluated.
    @
    ColorOverlay {
    Component.onCompleted: console.log(idItem1.children[index])
    }
    @



  • I made additional tests, and the weird thing is the following:

    • if I spot the children changes, the result is not the same as when the component has completed. Why?
      @import QtQuick 2.0
      import QtGraphicalEffects 1.0

    Item {
    id: idRoot
    width:800
    height:480

    property real nbrOfOccurences: 2
    
    Item {
        id: idItem1
        Repeater {
            id: idImagesRepeater
            model: nbrOfOccurences
            Item {
                id: idImage
                width: 100
                height: width
                x: width*index
            }
        }
    
        Repeater {
            model: nbrOfOccurences
            ColorOverlay {
                source: idItem1.children[index]
                onSourceChanged: {
                    print ("source for index "+index+" is "+source)
                }
            }
        }
        onChildrenChanged:  {
            print ("children Changed ")
            var i=0
            for (;i< 10;i++)  {
                print("idItem1.children[ "+i+"] "+idItem1.children[i] )
            }
        }
    }
    
    Component.onCompleted: {
        print ("Component on Completed ")
        var i=0
        for (;i< 10;i++)  {
            print("idItem1.children[ "+i+"] "+idItem1.children[i] )
        }
    }
    

    }

    @

    children Changed
    idItem1.children[ 0] QQuickRepeater(0x632410)
    idItem1.children[ 1] QQuickRepeater(0x631930)
    idItem1.children[ 2] ColorOverlay_QMLTYPE_1(0x631e70)
    idItem1.children[ 3] undefined
    idItem1.children[ 4] undefined
    idItem1.children[ 5] undefined
    idItem1.children[ 6] undefined
    idItem1.children[ 7] undefined
    idItem1.children[ 8] undefined
    idItem1.children[ 9] undefined
    source for index 0 is QQuickRepeater(0x632410)
    children Changed
    idItem1.children[ 0] QQuickRepeater(0x632410)
    idItem1.children[ 1] ColorOverlay_QMLTYPE_1(0x631e70)
    idItem1.children[ 2] QQuickRepeater(0x631930)
    idItem1.children[ 3] ColorOverlay_QMLTYPE_1(0x6acbf0)
    idItem1.children[ 4] undefined
    idItem1.children[ 5] undefined
    idItem1.children[ 6] undefined
    idItem1.children[ 7] undefined
    idItem1.children[ 8] undefined
    idItem1.children[ 9] undefined
    source for index 1 is ColorOverlay_QMLTYPE_1(0x631e70)
    children Changed
    idItem1.children[ 0] QQuickRepeater(0x632410)
    idItem1.children[ 1] ColorOverlay_QMLTYPE_1(0x631e70)
    idItem1.children[ 2] ColorOverlay_QMLTYPE_1(0x6acbf0)
    idItem1.children[ 3] QQuickRepeater(0x631930)
    idItem1.children[ 4] QQuickItem(0x6ac0b0)
    idItem1.children[ 5] undefined
    idItem1.children[ 6] undefined
    idItem1.children[ 7] undefined
    idItem1.children[ 8] undefined
    idItem1.children[ 9] undefined
    _children Changed _
    idItem1.children[ 0] QQuickItem(0x6ac0b0)
    idItem1.children[ 1] QQuickRepeater(0x632410)
    idItem1.children[ 2] ColorOverlay_QMLTYPE_1(0x631e70)
    idItem1.children[ 3] ColorOverlay_QMLTYPE_1(0x6acbf0)
    idItem1.children[ 4] QQuickRepeater(0x631930)
    idItem1.children[ 5] QQuickItem(0x6ace90)
    idItem1.children[ 6] undefined
    idItem1.children[ 7] undefined
    idItem1.children[ 8] undefined
    idItem1.children[ 9] undefined

    source for index 0 is QQuickItem(0x6ac0b0)
    source for index 1 is QQuickRepeater(0x632410)
    Component on Completed
    idItem1.children[ 0] QQuickItem(0x6ac0b0)
    idItem1.children[ 1] QQuickItem(0x6ace90)
    idItem1.children[ 2] QQuickRepeater(0x632410)
    idItem1.children[ 3] ColorOverlay_QMLTYPE_1(0x631e70)
    idItem1.children[ 4] ColorOverlay_QMLTYPE_1(0x6acbf0)
    idItem1.children[ 5] QQuickRepeater(0x631930)
    idItem1.children[ 6] undefined
    idItem1.children[ 7] undefined
    idItem1.children[ 8] undefined
    idItem1.children[ 9] undefined

    How come the last children change event, does not reflect the same order of children as when the component is completed? Shouldn't it be necessary to have another children change event inbetween that would reflect the same order as when the component has completed?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.