Details
-
Bug
-
Resolution: Incomplete
-
Not Evaluated
-
None
-
4.7.4
-
None
-
MAC 64 bit Lion 10.7
Description
#include "myclass.h"
#include <QDir>
#include <QString>
#include <Qdebug>
#include <QFileSystemModel>
myclass::myclass(QObject *parent)
: QSortFilterProxyModel(parent)
{
}
bool myclass::filterAcceptsRow ( int source_row, const QModelIndex & source_parent ) const
{
QModelIndex index = sourceModel()->index(source_row, 0/column/, source_parent);
QFileSystemModel* filemodel = qobject_cast<QFileSystemModel*>(sourceModel());
QFileInfo indexInfo = filemodel->fileInfo(index);
//qDebug () << files << files.contains("Setting.dB");
if (indexInfo.fileName()==QString("Setting.dB"))
{ return true; }else return false;
/*
if( indexInfo.isDir())
return true;
else if (indexInfo.isFile() && indexInfo.fileName() == QString("Setting.dB"))
return true;
else return false;
*/
}
In another class
void Login::on_loginbrowse_clicked()
{
// selecting a new setting.dB file
//QSortFilterProxyModel *filterModel = new QSortFilterProxyModel(parent);
//filterModel->setSourceModel(stringListModel);
QFileDialog *fileDialog = new QFileDialog;
//you implemented MyClass as proxy model so you need to set it in QFileDialog as proxyModel
myclass *proxyModel = new myclass;
fileDialog->setProxyModel(proxyModel);
fileDialog->show();
}
Result
Window showing all files and not the required one which is wrong