Results 1 to 13 of 13

Thread: representation of path selected from filedialog in the tree form

  1. #1
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Question 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

  2. #2
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default 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.

  3. #3
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Question 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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: representation of path selected from filedialog in the tree form

    How about:
    Qt Code:
    1. QString path;
    2. QStringList slist = QStringList::split("/", path);
    3. QListViewItem *item = 0;
    4. while(!slist.empty()){
    5. QString elem = slist.front();
    6. slist.pop_front();
    7. if(!item){
    8. item = new QListViewItem(&lv);
    9. } else {
    10. item = new QListViewItem(item);
    11. }
    12. item->setText(elem);
    13. }
    To copy to clipboard, switch view to plain text mode 

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

    merry (6th February 2007)

  6. #5
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Smile 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..
    Last edited by merry; 6th February 2007 at 06:38. Reason: Code u sent is Correct

  7. #6
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default 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

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: representation of path selected from filedialog in the tree form

    Quote Originally Posted by merry View Post
    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.

    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...

  9. The following user says thank you to wysota for this useful post:

    merry (6th February 2007)

  10. #8
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default 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.

  11. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: representation of path selected from filedialog in the tree form

    Oh come on, what is there to explain?

    Qt Code:
    1. QStringList slist = QDir("/etc/").entryList();
    2. for(QStringListIterator it = slist.begin(); it!=slist.end(); ++it){
    3. new QListViewItem(*it, listview);
    4. }
    To copy to clipboard, switch view to plain text mode 

  12. #10
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: representation of path selected from filedialog in the tree form

    Hi

    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

    Qt Code:
    1. #include <qfiledialog.h>
    2. #include <qapplication.h>
    3. #include <qlistview.h>
    4. #include <qstring.h>
    5. #include <qfile.h>
    6. #include <qfileinfo.h>
    7. #include <qstringlist.h>
    8. #include<qmessagebox.h>
    9. #include <qpixmap.h>
    10. #include <qcheckbox.h>
    11. #include <qdir.h>
    12. #include <qstringlist.h>
    13. #include <qmessagebox.h>
    14.  
    15. void Form1::fileOpen()
    16. {
    17.  
    18. m_source = QFileDialog::getExistingDirectory(
    19. "/",
    20. this,
    21. "get existing directory",
    22. "Choose a directory",
    23. TRUE );
    24. setDir(m_source);
    25. }
    26.  
    27. void Form1::setDir(QString path)
    28. {
    29.  
    30. QListViewItemIterator it(listView);
    31. ++it;
    32. for(;it.current();++it)
    33. {
    34. it.current()->setOpen(FALSE);
    35. }
    36.  
    37.  
    38. QStringList slist;
    39. QDir dir(path);
    40. QListViewItem * item;
    41. item->firstChild();
    42. slist=QStringList::split("/",path);
    43. slist=dir.entryList();
    44. QStringList::Iterator it2=slist.begin();
    45. for(;it2!=slist.end();++it2)
    46. {
    47. while(item)
    48. {
    49. if(item->text(0)=*it2)
    50. {
    51. item->setOpen(TRUE);
    52. break;
    53. }
    54. item=item->itemBelow();
    55.  
    56. }
    57.  
    58. }
    59.  
    60. if ( item )
    61. listView->setCurrentItem( item );
    62.  
    63.  
    64. }
    To copy to clipboard, switch view to plain text mode 

    If there is some alterations in this code then also tell me.

    Thanx
    Last edited by wysota; 7th February 2007 at 10:24. Reason: missing [code] tags

  13. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.

  14. The following user says thank you to wysota for this useful post:

    merry (7th February 2007)

  15. #12
    Join Date
    Jan 2007
    Posts
    326
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X

    Default 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

  16. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: representation of path selected from filedialog in the tree form

    Make sure you initialize all of the variables you use in Form1::setDir().

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.