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

    Thanx 4 the reply

    But it be better if You explain it with me the help of an example or code.

  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

    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 

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

    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

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

    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.

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

    merry (7th February 2007)

  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

    Thanx 4 ur reply and I also dont want YOU to debug for me.

    Once again Thanx

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