Details
-
Suggestion
-
Resolution: Unresolved
-
P4: Low
-
4.7.1
-
None
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.