Is that bug ?
-
hi everybody
i use gui application and this is my mainwindow.cpp
@
#include "mainwindow.h"
#include "ui_mainwindow.h"MainWindow::~MainWindow()
{
delete ui;
}MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);dirModal = new QFileSystemModel( this ); dirModal->setRootPath( "C:/" ); dirModal->setFilter( QDir::AllDirs | QDir::NoDotAndDotDot ); ui->treeView->setModel( dirModal ); fileModal = new QFileSystemModel( this ); fileModal->setRootPath( "C:/" ); fileModal->setFilter( QDir::Files | QDir::NoDotAndDotDot ); ui->listView->setModel( fileModal );
}
void MainWindow::on_treeView_clicked(const QModelIndex &index)
{
QString str = dirModal->fileInfo( index ).absoluteFilePath();
ui->listView->setRootIndex( fileModal->setRootPath( str ) );
}
@the first time work correctly but when you iterate directory the listView display wrong item ! for exmple you go tu directory 'a' in this directory exist some file and other dirctory you click on one directory in subdirectory of 'a' and then again click on 'a' directory !
i use qt creator 2.5 and qt 4.8.2 visual 2008
-
Did you take care of this?
QFileSystemModel::setRootPath()
Sets the directory that is being watched by the model to newPath by installing a file system watcher on it. Any changes to files and directories within this directory will be reflected in the model. Note: This function does not change the structure of the model or modify the data available to views. In other words, the "root" of the model is not changed to include only files and directories within the directory specified by newPath in the file system.So you may want to try to simply keep the root path at "C:", so the model keeps the data up-to-date for the complete drive. Actually I tend to call model.setRootPath("") once in my program and don't change it afterwards.
-
@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QtGui>
namespace Ui {
class MainWindow;
}class MainWindow : public QMainWindow
{
Q_OBJECTpublic:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();QFileSystemModel *dirModel; QFileSystemModel *fileModel;
private slots:
void on_treeView_clicked(const QModelIndex &index);private:
Ui::MainWindow *ui;
};#endif // MAINWINDOW_H
@and
@
#include "mainwindow.h"
#include "ui_mainwindow.h"MainWindow::~MainWindow()
{
delete ui;
}MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);dirModel = new QFileSystemModel( this ); dirModel->setFilter( QDir::NoDotAndDotDot | QDir::AllDirs ); dirModel->setRootPath( "" ); ui->treeView->setModel( dirModel ); fileModel = new QFileSystemModel( this ); fileModel->setFilter( QDir::NoDotAndDotDot | QDir::Files ); ui->listView->setModel( fileModel );
}
void MainWindow::on_treeView_clicked(const QModelIndex &index)
{
QString str = dirModel->fileInfo( index ).absoluteFilePath();ui->listView->setRootIndex( fileModel->setRootPath( str ) );
}
@in treeView shown directory and other side of treeView, listView that shown files in dir on selected in treeView ! there is one bug when you active like
go to directory ‘a’ . in this directory exist some file and other dirctory you click on one directory in subdirectory of ‘a’ and then again click on ‘a’ directory ! you will see subdirectory break filter and display in listView !!