Visualdatamodel and rootindex not working



  • Hi,

    I have a c++ QAbstractItemModel (tree) and I wants to display in a ListView some parts of the tree. so I use VisualDataModel and RootIndex to set the parent index in the C++ tree. the first time I create the declarativeView, the Listview has always the QModelIndex() first root note as rootIndex even If i set correctly the rootIndex in qml. If I delete the declarativeView and reload the same Qml with the previous created C++ tree, it works fine :the root index is correct !!!! I have check all my code and I am a little bit mad now ... I don't understand what's happen ( I have QT4.7.1 on windows msvc, and I have tryed also the latest git snapshot ...). I have this pseudo code :

    @
    VisualDataModel
    {
    id: outputModel
    model:computerModel
    delegate:outputDelegate
    rootIndex:controller.computerModelIndex("ComputerData"); // C++ function that return the correct QModelIndex (checked in debug)
    }

        ListView {
            id: outputListView
            model:outputModel
        }
    

    @

    I don't know if I have done a mistake or if it's a bug in the declarative lib ?



  • As a workaround, does setting the index at component completion cause it to work properly? e.g.

    @Component.onCompleted: {
    outputModel.rootIndex = controller.computerModelIndex("ComputerData")
    }@



  • yes .... I have tryed and all other option you can imagine :) ... set the model on the Listview when Component.onCompleted, use a button to set the rootIndex.... it go always to the root item the first time the declarativeview is created, and it's always ok after when I create a declarativeview ... strange !



  • Hi,

    It certainly sounds like a bug -- could you report it with a simple example to reproduce at http://bugreports.qt.nokia.com?

    Thanks,
    Michael


Log in to reply
 

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