[Development] Role names and Proxy Models

Olivier Goffart olivier at woboq.com
Mon Jan 16 13:21:19 CET 2012


On Monday 16 January 2012 02:13:44 Stephen Kelly wrote:
[...]
> If QML doesn't re-read the rolenames when the model is reset, then there's a
> patch to be made in QtDeclarative. (QAbstractProxyModel doesn't re-read
> them on reset either. Ogoffart rejected my patch to make it do that for
> reasons which never made sense to me and which I now forget and can't find
> on the internet).

I don't recall all the details either, but if I remember correctly, your patch 
was doing things that were not allowed. 
The role name feature is a bit broken as you can't really modify them. (As 
usual with features that are added to Qt in a rush by the decarative team for 
their own use cases, without much thinking ahead)

The documentation say: 
"This function allows mapping of role identifiers to role property names in 
Declarative UI. This function must be called before the model is used. 
Modifying the role names after the model has been set may result in undefined 
behaviour."

And you were calling it while the model was already in use, and I think it was 
the reason why I rejected.

> Anyway the Qt 5.0 way to set rolenames is to implement a virtual method.
> Please see if that addresses your concern, and if it doesn't, then please
> write an example which doesn't require a proxy which hides 'multiple
> underlying models'. That might not work anyway for various reasons (if you
> are using QAbstractProxyModel). Use an example such as 'a proxy model which
> returns a string filename for an image instead of a QImage for the
> decoration role'.

I think Qt 5 still do not implement ways to notify that the role name change.




More information about the Development mailing list