PDA

View Full Version : Notifying QFileSystemModel about changes



squidge
23rd November 2009, 21:28
I have a QFileSystemModel with a custom QSortFilterProxyModel and a custom QFileIconProvider.

My QFileIconProvider fetches file icons in another thread so that the file list can be populated more quickly - get file list first, populate list, and then get the icons in a seperate thread. So my QFileIconProvider::icon() override returns a blank icon until the information is available. How can I get QFileSystemModel to recognise when the new icon is available? I don't want want to refresh the entire list, as I want the list to update as and when the icons become available.

wysota
23rd November 2009, 22:07
Emit dataChanged() for each modified index.

squidge
23rd November 2009, 23:10
I would normally use that in a model to notify the widget that the data is changed and to refresh it. However, here I don't control the data in the model as it's a QFileSystemModel, and since QFileSystemModel caches the data, will dataChanged actually have any effect? Or will it just retrieve the data from the cache ?

I know it can handle changes from its thread internally, but thats all hidden in QFileSystemModelPrivate.

wysota
23rd November 2009, 23:24
It's best to just check what QFileSystemModel::data() returns for decoration (and FileIconRole) role. I would guess emitting dataChanged() is the only thing you can do with the model here. Otherwise apply a proxy over the model and return icons from the proxy - then you'll have full control over what is going on.