PDA

View Full Version : QDirModel's index overloaded function



psih128
31st December 2009, 01:52
Hi

There is an issue with QDirModel that has been puzzling me for quite some time. There is a public function in this class with the following signature:

QModelIndex index(const QString &path, int column = 0) const;

I have another class that inherits QDirModel:


class MyDirModel : public QDirModel {
}

now when I do something like in this:


MyDirModel model;
QModelIndex index = model.index(QString("/Users/anton"), 0);

it would give compilation error:


no matching function for call to 'MyDirModel::index(QString, int)'

To workaround this I usually do something like this:


MyDirModel *model;
qobject_cast<QDirModel *>(model)->index(QString('..."), 0);

What's the trick here?

I'm on Qt 4.6 under Mac. Not sure if it's reproducible on Windows

Thanks
Anton

Coises
31st December 2009, 08:11
Does your sub-class re-implement the other QDirModel::index (the one that takes int row, int column, const QModelIndex& parent), or declare some other member function named “index”?

If so, that declaration hides all inherited functions by the same name. In that case, you could add:
using QDirModel::index; to the definition of your derived class to allow overload resolution of the name “index” to include member functions from QDirModel.