I\'ve been struggling with this for a while.
Qt\'s QFileSystemModel
is really slow when fetching several hundred files because of a really bad icon fetc
If a function in a base class is virtual then it is virtual in derived classes as well. The following will print "C":
#include <iostream>
class A {
public:
virtual void data() = 0;
};
class B: public A {
public:
void data() { std::cout << "B\n"; }
};
class C: public B {
public:
void data() { std::cout << "C\n"; }
};
int
main() {
C c;
A *a = &c;
a->data();
return 0;
}
QFileSystemDialog
is derived from QAbstractItemModel
in which data()
is pure virtual. You couldn't even instatiate the former if it didn't override data()
with its own implementation.
See http://qt-project.org/doc/qt-4.8/qabstractitemmodel.html#data
Looks like this was anticipated, as there is a method for setting the "icon provider":
http://doc.qt.io/archives/qt-4.7/qfilesystemmodel.html#setIconProvider
The parameter, a QFileIconProvider
, looks to be a fairly simple class that you can implement an instance of yourself, with a method that fetches an icon from a QFileInfo
(basically, a file name):
http://doc.qt.io/archives/qt-4.7/qfileinfo.html
You could implement one of these that just returns the same icon for everything. If you find that doesn't address your problem, the following compiled fine for me...FWIW:
class FileModel : public QFileSystemModel {
public:
QVariant data(const QModelIndex &index, int role) const
{
if (role == Qt::DecorationRole) {
return QVariant (QIcon ());
}
return QFileSystemModel::data(index, role);
}
};