i) why do you assign the role to your variable role?
(Looks like you are confused about default values...)

ii) check the return value of setData(); probably it is false.
Not every model supports setting data (or setting any role).


You can subclass QDirModel and have your subclass's data function return that icon for Qt:ecorationRole.

HTH