Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo 2 Support (Qt 5) › SwipeView with default index triggers onchange event with broken item

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #24628

    nks (baumemo)

    Hi,

    I have a strange issue with the SwipeView component. When using with a other default index set by binding the onItemChanged event get triggered with null item.

    What do I wrong. What can I do to get always a valid item? May be it is a bug?

    The output is:

    2
    null
    2
    null

    The Code:

    import Felgo 3.0
    import QtQuick 2.15
    import QtQuick.Controls 2.15 as QQC
    
    App {
        Page {
            id: currentPage
            title: "Demo"
            property int swipeDefaultIndex:2
    
    
            QQC.SwipeView {
                id: swipeView
    
                currentIndex: currentPage.swipeDefaultIndex
                anchors.fill: parent
    
                onCurrentItemChanged: {
                    console.log(currentIndex)
                    console.log(currentItem)
                }
                onCurrentIndexChanged: {
                    console.log(currentIndex)
                    console.log(currentItem)
                }
    
                Repeater {
                    model: 7
                    Item {
    
                    }
                }
            }
        }
    }
    

     

     

     

    #24633

    Alex
    Felgo Team

    Hi,

    indeed this looks like a bug in the Qt SwipeView, when initializing the view with a custom currentIndex. I extended the example a bit to further check that:

    import Felgo 3.0
    import QtQuick 2.15
    import QtQuick.Controls 2.15 as QQC
    
    App {
      Page {
        id: currentPage
        title: "Demo"
        property int swipeDefaultIndex:2
    
        Component.onCompleted: {
          // Using this will correctly trigger the signals, but will show visual transitions
          //swipeView.currentIndex = Qt.binding(function() {return currentPage.swipeDefaultIndex})
        }
    
        QQC.SwipeView {
          id: swipeView
    
          currentIndex: currentPage.swipeDefaultIndex
          anchors.fill: parent
    
          onCurrentItemChanged: {
            console.debug("onCurrentItemChanged")
            // You could ignore any calls where !currentItem
            console.log(currentIndex)
            console.log(currentItem)
          }
          onCurrentIndexChanged: {
            console.debug("onCurrentIndexChanged")
            // You could ignore any calls where !currentItem
            console.log(currentIndex)
            console.log(currentItem)
          }
    
          // Call this manually after completion will trigger again with correct data
          Component.onCompleted: currentItemChanged()
    
          Repeater {
            model: 7
            Item {
    
              Rectangle {
                anchors.fill: parent
                color: Qt.rgba(1,0,0,0.1*(index+1))
              }
            }
          }
        }
    
        Column {
          anchors.centerIn: parent
    
          AppButton {
            text: "Next"
            onClicked: currentPage.swipeDefaultIndex++
          }
    
          AppButton {
            text: "Prev"
            onClicked: currentPage.swipeDefaultIndex--
          }
    
          AppButton {
            text: "CurrentItem"
            onClicked: console.log(swipeView.currentItem)
          }
        }
      }
    }

    Manually triggering the signal after the component is completed seems to return the correct data, so that might be an option for you?

    Best,
    Alex

Viewing 2 posts - 1 through 2 (of 2 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded