Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Is that bug ?

    General and Desktop
    2
    5
    1646
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      ahura_24 last edited by

      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

      1 Reply Last reply Reply Quote 0
      • A
        ahura_24 last edited by

        i love Qt but its have too many bugs :(

        1 Reply Last reply Reply Quote 0
        • M
          MuldeR last edited by

          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.

          My OpenSource software at: http://muldersoft.com/

          Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

          Go visit the coop: http://youtu.be/Jay...

          1 Reply Last reply Reply Quote 0
          • A
            ahura_24 last edited by

            i write this code in one tutorial but this toturial base on 4.7.2 but i write on 4.8.2 :-??

            1 Reply Last reply Reply Quote 0
            • A
              ahura_24 last edited by

              @
              #ifndef MAINWINDOW_H
              #define MAINWINDOW_H

              #include <QtGui>

              namespace Ui {
              class MainWindow;
              }

              class MainWindow : public QMainWindow
              {
              Q_OBJECT

              public:
              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 !!

              1 Reply Last reply Reply Quote 0
              • First post
                Last post