representation of path selected from filedialog in the tree form
Hi all
i am new in QT3.1 on Linux red hat
and i have a problem with QListView
i have a main window on that i have file menu futher having open (item)
when i select open then it show a file dialog from where i can select a path
now i want that what ever i select the path that path should come out in a tree structure(in hierarchy ) like first folder is root , subfolder,sub sub folder,filesetc
please do help me for this problem
thanks in advance
Re: representation of path selected from filedialog in the tree form
Well,
Is it not already the case ?
I don't remember well with Qt3, but it seems a file dialog returns you the absolute path...
Do you have an example ?
Guilugi.
Re: representation of path selected from filedialog in the tree form
thanks for reply
yes exactly file dialog returns the path....
and now i want that path should be viewed in a tree(hierarchy) on my mainwindow form
please do tell with an example
waiting for reply
Re: representation of path selected from filedialog in the tree form
How about:
Code:
QListViewItem *item = 0;
while(!slist.empty()){
slist.pop_front();
if(!item){
item = new QListViewItem(&lv);
} else {
item = new QListViewItem(item);
}
item->setText(elem);
}
Re: representation of path selected from filedialog in the tree form
Want to Thank u Lots and Lots of time ...
The code u sent is working .. .. .....
Once again Thanx..
Re: representation of path selected from filedialog in the tree form
In this it displays the selected path in the form of tree but i want to display all the files and folders of the last item of the selected path that is last item of the selected path is root and it displays all the files and folders contained in the root item.
Foreg.
the selected path is /home/qt/etc
here in the selected path "etc" should be the root item and it displays all the files and folders contained in the "etc" in the the form of the tree structure.
Please reply me as soon as possible its really very very urgent
Thanx
Re: representation of path selected from filedialog in the tree form
Quote:
Originally Posted by
merry
In this it displays the selected path in the form of tree but i want to display all the files and folders of the last item of the selected path that is last item of the selected path is root and it displays all the files and folders contained in the root item.
And the problem is...?
QDir::entryList() or QDir::entryInfoList() will give you a list of entries in a particular directory. Just wrap the result into QListViewItems and you're done.
Quote:
Please reply me as soon as possible its really very very urgent
Please don't say that, it won't make anyone answer your post faster than without it...
Re: representation of path selected from filedialog in the tree form
Thanx 4 the reply
But it be better if You explain it with me the help of an example or code.
Re: representation of path selected from filedialog in the tree form
Oh come on, what is there to explain?
Code:
for(QStringListIterator it = slist.begin(); it!=slist.end(); ++it){
new QListViewItem(*it, listview);
}
Re: representation of path selected from filedialog in the tree form
Hi
:crying: I am sending u the code Please tell me its right or not for the representation of path in a tree structure form.
actually I got " segmentationfault "
Here the code is
Code:
#include <qfiledialog.h>
#include <qapplication.h>
#include <qlistview.h>
#include <qstring.h>
#include <qfile.h>
#include <qfileinfo.h>
#include <qstringlist.h>
#include<qmessagebox.h>
#include <qpixmap.h>
#include <qcheckbox.h>
#include <qdir.h>
#include <qstringlist.h>
#include <qmessagebox.h>
void Form1::fileOpen()
{
"/",
this,
"get existing directory",
"Choose a directory",
TRUE );
setDir(m_source);
}
{
QListViewItemIterator it(listView);
++it;
for(;it.current();++it)
{
it.current()->setOpen(FALSE);
}
QListViewItem * item;
item->firstChild();
slist=dir.entryList();
for(;it2!=slist.end();++it2)
{
while(item)
{
if(item->text(0)=*it2)
{
item->setOpen(TRUE);
break;
}
item=item->itemBelow();
}
}
if ( item )
listView->setCurrentItem( item );
}
If there is some alterations in this code then also tell me.
Thanx
Re: representation of path selected from filedialog in the tree form
Why don't you debug the code and see where it segfaults? This is only a snippet, so I can't debug it for you. Please use a debugger and print a backtrace to see where and why it crashes.
Re: representation of path selected from filedialog in the tree form
Thanx 4 ur reply:) and I also dont want YOU to debug for me.
Once again Thanx
Re: representation of path selected from filedialog in the tree form
Make sure you initialize all of the variables you use in Form1::setDir().