Results 1 to 12 of 12

Thread: How to display entire directory(Filesystem)

  1. #1
    Join Date
    Jun 2007
    Location
    India
    Posts
    33
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy How to display entire directory(Filesystem)

    Hi all
    I have attached a picture, please check that.
    It shows the 'Light Explorer' plugin for Notepad++. Basically, it lists down all the contents of the file system on the right hand pane and one can double click on a file to open it in notepad++.

    Could someone tell me how can I bring in that full directory tree? Any kind of help will be highly appreciated.

    What we are intending to create is a file previewer - Directory structure on left side and a basic text viewer on right side. So whenever a file is clicked on the left side, the text viewer should immediately show the contents of the file.

    Edit: This app is to be deployed in Fedora 7 machine even though i have taken the windows file structure as an example.

    Thanks a lot in advance
    Deepak
    Attached Images Attached Images
    Last edited by deepakn; 6th November 2009 at 05:57. Reason: Qt Platform specified

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to display entire directory(Filesystem)

    For directory structure data you need to use QDirModel. This model will give you data for underlign file structure. And you can use QTreeView to display that in the left pane of your desired application.
    On right habd pane you need to use QTextBrowser/QTextEdit/QSimpleTextBrowser.
    See this example:
    http://doc.trolltech.com/4.5/itemviews-dirview.html

  3. The following user says thank you to yogeshgokul for this useful post:

    deepakn (10th November 2009)

  4. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to display entire directory(Filesystem)

    I would have thought a QFileSystemModel would be better, coupled with a QTreeView. Its threaded, so doesn't handle the ui thread, and detects changes to the file system, applying them dynamically.

  5. The following user says thank you to squidge for this useful post:

    deepakn (10th November 2009)

  6. #4
    Join Date
    Oct 2009
    Posts
    151
    Thanks
    6
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to display entire directory(Filesystem)

    Hi,

    Deja Vu?

    You may be interested in my earlier post:

    "QT Designer 4.5" on 3rd November 2009 at 14:03

    You can of course substitute the QFileSystemModel in place of QDirModel as suggested by fatjuicymole.

  7. #5
    Join Date
    Jun 2007
    Location
    India
    Posts
    33
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to display entire directory(Filesystem)

    Hi all,
    Thanks a lot to everyone for the solutions. It really helped. That example alone was too helpful.

    I had been through JD2000's post. I too follow the same method of designing the UI and then programming the functionality into it.

    Now I am stuck with another (dumb)problem.
    I have this QDirModel inside a QTreeView as intended. Now I need to create a signal-slot relationship between 'clicked' on the treeView and a slot which does some manipulations on the file which is selected. My problem is that I am not able to return the filePath from the QDirModel/QTreeView as a string.
    I could find that
    Qt Code:
    1. QString QDirModel::filePath ( const QModelIndex & index ) const
    To copy to clipboard, switch view to plain text mode 
    does it, but I am not able to supply the index value of the currently selected item. How do I do it?

    This maybe a dumb question and I am sorry for it.
    Thanks for all the help

    Deepak

  8. #6
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to display entire directory(Filesystem)

    Quote Originally Posted by deepakn View Post
    QString QDirModel::filePath ( const QModelIndex & index ) const [/CODE] does it, but I am not able to supply the index value of the currently selected item. How do I do it?
    Lets say you want to do something when someone double clicks on any file in tree view.
    You need to connect the
    Qt Code:
    1. void doubleClicked ( const QModelIndex & index )
    To copy to clipboard, switch view to plain text mode 
    SIGNAL of the QTreeView.
    To your custom SLOT.
    In that slot, you can get the filePath easily because you have the QModelIndex with you.
    By calling
    Qt Code:
    1. QString QDirModel::fileName ( const QModelIndex & index ) const
    To copy to clipboard, switch view to plain text mode 

  9. #7
    Join Date
    Jun 2007
    Location
    India
    Posts
    33
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to display entire directory(Filesystem)

    Thanks a lot Yogesh. Now I have this question related to Model-View architecture( I am totally new to it. )

    How do I access the 'filePath' of this QDirModel from another function?

    Qt Code:
    1. fileLoader::fileLoader( QWidget *parent ) : QDialog( parent )
    2. {
    3. ui.setupUi( this );
    4.  
    5. //QFileSystemModel *model = new QFileSystemModel;
    6. QDirModel *model = new QDirModel;
    7. ui.tree->setModel(model);
    8.  
    9. connect(ui.tree, SIGNAL( doubleClicked( const QModelIndex & )), this, SLOT(previewFile( const QModelIndex & )));
    10.  
    11. }
    12.  
    13. void fileLoader::previewFile( const QModelIndex & index )
    14. {
    15. //QString filePath = ui.tree ->filePath( index );
    16. }
    To copy to clipboard, switch view to plain text mode 

    I know that
    QString filePath = ui.tree ->filePath( index );
    is wrong. But how do I access that particular function? What is the right procedure to do it?

  10. #8
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to display entire directory(Filesystem)

    There is a significant problem with your code.
    Qt Code:
    1. QDirModel *model = new QDirModel;
    To copy to clipboard, switch view to plain text mode 
    Should be a class level variable.

    Quote Originally Posted by deepakn View Post
    I know that is wrong. But how do I access that particular function? What is the right procedure to do it?
    Qt Code:
    1. void fileLoader::previewFile( const QModelIndex & index )
    2. {
    3. QString strFileName = model->fileName(index);
    4. QFile f(strFileName);
    5. if(f.open(QIOdevice::ReadOnly))
    6. {
    7. QString data = f.readAll();
    8. f.close();
    9. yourTextWidget->setText(data);
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

  11. #9
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: How to display entire directory(Filesystem)

    Quote Originally Posted by deepakn View Post
    Hi all
    I have attached a picture, please check that.
    It shows the 'Light Explorer' plugin for Notepad++. Basically, it lists down all the contents of the file system on the right hand pane and one can double click on a file to open it in notepad++.

    Could someone tell me how can I bring in that full directory tree? Any kind of help will be highly appreciated.

    What we are intending to create is a file previewer - Directory structure on left side and a basic text viewer on right side. So whenever a file is clicked on the left side, the text viewer should immediately show the contents of the file.

    Edit: This app is to be deployed in Fedora 7 machine even though i have taken the windows file structure as an example.

    Thanks a lot in advance
    Deepak
    You can also list all the directories, subdirectries, files (hidden also) using
    ls -Ra
    command and QProcess object.
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  12. #10
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to display entire directory(Filesystem)

    Quote Originally Posted by ashukla View Post
    You can also list all the directories, subdirectries, files (hidden also) using
    ls -Ra
    command and QProcess object.
    And how many years it will take to display that structure in a tree view

  13. #11
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to display entire directory(Filesystem)

    Quote Originally Posted by ashukla View Post
    You can also list all the directories, subdirectries, files (hidden also) using
    ls -Ra
    command and QProcess object.
    Not exactly portable though is it?

  14. #12
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to display entire directory(Filesystem)

    Quote Originally Posted by deepakn View Post
    How do I access the 'filePath' of this QDirModel from another function?
    As yogeshgokul says is one way of doing it, and the cleanest. Or you could use the modal() method of the treeview, cast it to a QDirModel and use that. It all depends on the access you have to appropriate variables.

Similar Threads

  1. How to display a double?
    By TomASS in forum Qt Programming
    Replies: 3
    Last Post: 29th May 2009, 20:15
  2. synchronise QLabel display and webcam capture
    By fbmfbm in forum Qt Programming
    Replies: 2
    Last Post: 24th February 2009, 11:10
  3. OS/X how to get physical display handle
    By hvengel in forum Qt Programming
    Replies: 4
    Last Post: 3rd January 2009, 19:51
  4. Display only PNG image on desktop
    By durbrak in forum Qt Programming
    Replies: 32
    Last Post: 15th March 2008, 21:55
  5. Graphics view display problem.
    By kiranraj in forum Qt Programming
    Replies: 3
    Last Post: 20th July 2007, 07:08

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.