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. Visualdatamodel and rootindex not working
Forum Updated to NodeBB v4.3 + New Features

Visualdatamodel and rootindex not working

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 2.8k Views 1 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.
  • Q Offline
    Q Offline
    qtnext
    wrote on last edited by
    #1

    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 ?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mbrasser
      wrote on last edited by
      #2

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

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

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qtnext
        wrote on last edited by
        #3

        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 !

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mbrasser
          wrote on last edited by
          #4

          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

          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