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

QModelIndex should be special cased to allow data access

    XMLWordPrintable

Details

    Description

      It is not possible in QML to invoke the QModelIndex::data(int role) method. This makes it hard to access data from an index where the data is not related to a particular index.

      In the example I attached I try to create a file system viewer. I try to display the current path, which is not possible directly. I have to create a Q_INVOKABLE to invoke the c++ api for that. This is more complicated than it needs to be.

      It should be possible to to something like myModel.rootIndex.filePath, where filePath could be any roleName registered with setRoleNames.

      That is, any time I can access a QModelIndex in QML, it should be possible to call its data() method to retrieve particular data.

      That would allow me to be declarative in the value that I show for the current path:

      Text

      { id : currentPathText anchors.centerIn : parent text : qmlDataModel.rootIndex.filePath }

      Instead of the Q_INVOKABLE and onRootIndexChanged which I had to use in this case.

      Adding a indexAt(int) method to VisualDataModel would also make this far more useful.

      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
            steveire Stephen Kelly (Personal)
            Votes:
            6 Vote for this issue
            Watchers:
            10 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes