1 Attachment(s)
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
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
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.
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.
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 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
Re: How to display entire directory(Filesystem)
Quote:
Originally Posted by
deepakn
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 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
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?
Code:
{
ui.setupUi( this );
//QFileSystemModel *model = new QFileSystemModel;
ui.tree->setModel(model);
connect(ui.
tree,
SIGNAL( doubleClicked
( const QModelIndex & )),
this,
SLOT(previewFile
( const QModelIndex & )));
}
void fileLoader
::previewFile( const QModelIndex & index
) {
//QString filePath = ui.tree ->filePath( index );
}
I know that
Quote:
QString filePath = ui.tree ->filePath( index );
is wrong. But how do I access that particular function? What is the right procedure to do it?
Re: How to display entire directory(Filesystem)
There is a significant problem with your code.
Should be a class level variable.
Quote:
Originally Posted by
deepakn
I know that is wrong. But how do I access that particular function? What is the right procedure to do it?
Code:
void fileLoader
::previewFile( const QModelIndex & index
) {
QString strFileName
= model
->fileName
(index
);
if(f.open(QIOdevice::ReadOnly))
{
f.close();
yourTextWidget->setText(data);
}
}
Re: How to display entire directory(Filesystem)
Quote:
Originally Posted by
deepakn
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.
Re: How to display entire directory(Filesystem)
Quote:
Originally Posted by
ashukla
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 :D
Re: How to display entire directory(Filesystem)
Quote:
Originally Posted by
ashukla
You can also list all the directories, subdirectries, files (hidden also) using
ls -Ra
command and QProcess object.
Not exactly portable though is it?
Re: How to display entire directory(Filesystem)
Quote:
Originally Posted by
deepakn
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.