QDirModel with QSortFilterProxyModel and regexp
Hello,
I'm trying to create a QDirModel that only shows .cpp files but it doesn't display anything.
What am I doing wrong?
Code:
dirModel.
setFilter( QDir::AllDirs |
QDir::Files |
QDir::NoDotAndDotDot );
proxyModel.setSourceModel(&dirModel);
tree.setModel(&proxyModel);
QModelIndex idx
= proxyModel.
mapFromSource(dirModel.
index("./") );
tree.setRootIndex(idx);
proxyModel.
setFilterRegExp(QRegExp(".cpp", Qt
::CaseInsensitive,
QRegExp::FixedString));
proxyModel.setFilterKeyColumn(0);
tree.setAnimated(false);
tree.setIndentation(20);
tree.setSortingEnabled(true);
tree.
setWindowTitle(QObject::tr("Dir View"));
tree.resize(640, 480);
tree.show();
Re: QDirModel with QSortFilterProxyModel and regexp
assuming you want all files with the extension .cpp that would be one of
Code:
QRegExp("\\.*.cpp", Qt
::CaseInsensitive)
Your regexp only matches files named ".cpp" without anything in front of it.
HTH
Re: QDirModel with QSortFilterProxyModel and regexp
...or QRegExp(".*\\.cpp").
I'm not sure about mapping the slashdot like that, by the way.
Re: QDirModel with QSortFilterProxyModel and regexp
Quote:
Originally Posted by
caduel
assuming you want all files with the extension .cpp that would be one of
Code:
QRegExp("\\.*.cpp", Qt
::CaseInsensitive)
Your regexp only matches files named ".cpp"
without anything in front of it.
HTH
Sorry, forgott to mention that I tried your approach to, this does not work, I just get a empty list.
Re: QDirModel with QSortFilterProxyModel and regexp
Quote:
Originally Posted by
wysota
...or QRegExp(".*\\.cpp").
I'm not sure about mapping the slashdot like that, by the way.
How should I map it any other way? I tried to map it to "/Users/mchrk/code/foo/src/" and I got the same result as before (nothing).
Re: QDirModel with QSortFilterProxyModel and regexp
@Wysota: oops... that was wrong of course. the \\ indeed has to be in front of the second .
@mchrk: have you checked if it works without setting a rootIndex?
have you checked that proxyModel.mapFromSource(dirModel.index("./") ) yields a valid QModelIndex?
Re: QDirModel with QSortFilterProxyModel and regexp
Quote:
Originally Posted by
caduel
@Wysota: oops... that was wrong of course. the \\ indeed has to be in front of the second .
@mchrk: have you checked if it works without setting a rootIndex?
have you checked that proxyModel.mapFromSource(dirModel.index("./") ) yields a valid QModelIndex?
Yes I checked the model index with idx.isValid() and it returns true.