2 Attachment(s)
QFileSystemModel::setFilter issue!!
Hi all:
I am trying to construct a custom file manager, using QListview, QTreeview, and two QFileSystemModel!!
The QListview is set with the QFileSystemModel( Listmodel ) which is setFilter like the code below:
Code:
setFilter
( QDir::Files |
QDir::NoDotAndDotDot |
QDir::NoSymLinks );
The QTreeview is set with the QFilesystemModel which is setFilter like the code below:
Code:
setFilter
( QDir::AllDirs |
QDir::NoDotAndDotDot |
QDir::NoSymLinks );
When the file manager shows up at the beginning, everything looks perfect as the first attach file.
But after few steps, the filter in the Listmodel seems to become invalid as the second attach file.
1. Double click a folder called "test", which includes a subfolder, in the treeview. And the subfolder icon shows up.
2. Choose a subfolder of the folder "test", then the listview shows the files in the subfolder
3. Choose back to the folder "test", and the listview shows all files in the folder including the subfolder.
The result is not correct with the filter being set to the Listmodel!!!
Could anyone tell me what's wrong?!?!?
Thanks in advanced.
Kenny
Re: QFileSystemModel::setFilter issue!!
I am afraid that there is some filter resetting in your code that creates the mess. Provide smallest possible working code that reproduces the problem.
Re: QFileSystemModel::setFilter issue!!
Thank you for your reply.
I've tried to make another simple test project.
And the code in MainWindow.cpp is pretty simple as below:
Code:
void MainWindow::OnTreeClicked( const QModelIndex& idx )
{
QFileInfo kFolderinfo
= m_pTreeModel
->filePath
( idx
);
ui->listView->setRootIndex( m_pListModel->setRootPath( kFolderinfo.filePath() ) );
}
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow),
m_pListModel( NULL ),
m_pTreeModel( NULL )
{
m_pListModel = new QFileSystemModel();
m_pTreeModel = new QFileSystemModel();
ui->setupUi(this);
ui->listView->setModel( m_pListModel );
m_pListModel
->setFilter
( QDir::NoDotAndDotDot |
QDir::Files );
QModelIndex kListidx
= m_pListModel
->setRootPath
( strListFolder
);
ui->listView->setRootIndex( kListidx );
ui->treeView->setModel( m_pTreeModel );
m_pTreeModel
->setFilter
( QDir::NoDotAndDotDot |
QDir::AllDirs );
ui->treeView->setRootIsDecorated( false );
QModelIndex kTreeidx
= m_pTreeModel
->setRootPath
( strDesktop
);
ui->treeView->setRootIndex( kTreeidx );
connect( ui->treeView, SIGNAL( clicked( const QModelIndex& ) ), this, SLOT( OnTreeClicked( const QModelIndex& ) ) );
}
This simple project also make the same issue.
After the test project, I've do some search.
And I have found out the doc Qt 4.4 QFileSystemModel tells that the function, setRootPath, will reset the model while the path is changed!!!
I cannot figure out the word "reset", and whether it is related to weird issur or not.
And the related description is not shown in Qt 4.7 QFileSystemModel.
btw, I am using Qt 4.7.
Thanks in advanced.
Kenny
Re: QFileSystemModel::setFilter issue!!
If you don't have to use QFileSystemModel and you can live with QDirModel, then following code should solve your problem:
Code:
void MainWindow::OnTreeClicked( const QModelIndex& idx )
{
QFileInfo kFolderinfo
= m_pTreeModel
->filePath
( idx
);
m_pListModel->refresh(m_pListModel->index(kFolderinfo.filePath()));
ui->listView->setRootIndex( m_pListModel->index(kFolderinfo.filePath() ) );
}
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow),
m_pListModel( NULL ),
m_pTreeModel( NULL )
{
ui->setupUi(this);
ui->listView->setModel( m_pListModel );
m_pListModel
->setFilter
( QDir::NoDotAndDotDot |
QDir::Files );
ui->listView->setRootIndex( m_pListModel->index(strDesktop) );
ui->treeView->setModel( m_pTreeModel );
m_pTreeModel
->setFilter
( QDir::NoDotAndDotDot |
QDir::AllDirs );
ui->treeView->setRootIsDecorated( false );
ui->treeView->setRootIndex( m_pTreeModel->index(strDesktop) );
connect( ui->treeView, SIGNAL( clicked( const QModelIndex& ) ), this, SLOT( OnTreeClicked( const QModelIndex& ) ) );
}
Re: QFileSystemModel::setFilter issue!!
Thanks for your reply!!
And I've tried to use QDirModel, it really work!!
But I really have to use QFileSystemMode because of some reasons:
1. The file manager needs the functions applied by the watcher.
2. The performance difference between QDirModel and QFileSystemModel is what I concern, so I use QFileSystemModel.
any idea??
The test project and files could be download here.