Results 1 to 13 of 13

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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 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...

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

    merry (6th February 2007)

  4. #3
    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.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 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 

  6. #5
    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 09:24. Reason: missing [code] tags

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 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.

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

    merry (7th February 2007)

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

  10. #8
    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
  •  
Qt is a trademark of The Qt Company.