0

I am trying to implement Custom File Explorer that fetches metadata of the specific(in house file system) file and displays all these data along with files. For this task I have implemented custom QFileSystemModel that takes care of this.

Now, I understand that loading of file is asynchronous in QFileSystemModel but display is not. Qt holds display job till all the files are loaded. As i have included metadata extraction logic in each display call, it makes display of folder with more than 100 file really slow(even after caching). During whole this time display is completely blocked. How can I display results asynchronously. To be precise display list partly and then refresh it when updates are available.

Files are displayed through QTableView UI widget.

Minhaz
  • 15
  • 5

1 Answers1

0

1.You can put your extraction logic in a different thread. Look here how to do that:http://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/
If you use a shared data don't forget to use a mutex. Also you can send new meta from the new thread to GUI via signals with an argument containing the meta info. In this way you'll need to register a new class with qRegisterMetaType and Q_DECLARE_METATYPE to make it possible to convert it to QVariant and back:
http://qt-project.org/doc/qt-4.8/qmetatype.html

2.Also you can make the files load much faster if you disable loading of icons. For example, if you have only one type of files you can provide an icon preloaded from the resources.
This is how to disable loading of icons:

a) Create a fake icons provider:

class FakeIconProvider : public QFileIconProvider
{
public:
  FakeIconProvider();
  virtual QIcon icon(IconType) const override
  {
     return QIcon();
  }
  virtual QIcon icon(const QFileInfo&) const override
  {
     return QIcon();
  }
};

b) Create an instance of the fake icons provider and install it to the model:

 model->setIconProvider(m_fakeIconProvider);
Ezee
  • 4,214
  • 1
  • 14
  • 29
  • Ok. Your Idea is really awesome. I implemented it, it does work but to a point where I am ready to print metadata in the column. But I don't know why, I am facing hard time to display that data in column. I captured the event with metadata in my custom QFileSystemModel method, which calls setData(QVariant, Index, Role ) and reset view. It does not work. Any help – Minhaz Aug 18 '14 at 02:57
  • You shouldn't use `setData` if you haven't reimplemented it, because `QFileSystemModel::setData` actually renames files which is wrong behaviour in your case. Instead you need to store your metadata somewhere and `emit dataChanged(...)`. Also reimplement `data` method of the model and provide something like this: `if (role == Qt::DisplayRole) return QFileSystemModel::data(index, role) + metadata(index);` – Ezee Aug 18 '14 at 05:27