Results 1 to 4 of 4

Thread: [solved]Get filepath and filename from qtreewidget

  1. #1
    Join Date
    Mar 2010
    Posts
    54
    Qt products
    Qt/Embedded
    Platforms
    Symbian S60

    Default [solved]Get filepath and filename from qtreewidget

    Hi
    I have a strange issue where I need to get filepath and filename on a single click of the item in the qtreewidget

    Qt Code:
    1. class browserwindow: public QTreeWidget
    2. {
    3. Q_OBJECT
    4. public:
    5. browserwindow(QWidget* parent = 0);
    6. ~browserwindow();
    7. //functions
    8. void populate();
    9.  
    10. public slots:
    11.  
    12. QModelIndex getDetails(const QModelIndex& index);
    13.  
    14. public:
    15. QDirModel* model;
    16. QTreeView* tree;
    17. QModelIndex index;
    18.  
    19. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "browsemodel.h"
    2.  
    3. browserwindow::browserwindow(QWidget* parent)
    4. :QTreeWidget(parent)
    5. {
    6. model = new QDirModel(this);
    7. tree = new QTreeView(this);
    8. populate();
    9.  
    10. }
    11.  
    12. browserwindow::~browserwindow()
    13. {
    14. delete tree;
    15. delete model;
    16. }
    17.  
    18. void browserwindow::populate()
    19. {
    20. tree->setModel(model);
    21. tree->setRootIndex(model->index(QDir::homePath()));
    22. tree->setWindowTitle("Browse for folder");
    23. tree->resize(820, 7200);
    24. connect(this,SIGNAL(clicked(QModelIndex)),SLOT(getDetails(QModelIndex)),Qt::DirectConnection);
    25.  
    26. }
    27.  
    28. QModelIndex browserwindow::getDetails(const QModelIndex &index) // to get details on the index on single click
    29. {
    30. QString filename = model->fileName(index);
    31. return model->index(0);
    32.  
    33. }
    To copy to clipboard, switch view to plain text mode 
    Issue is that I get a SIGSERV segmentation fault when I run the above code
    my main objective is that , when a user clicks on the "browse" button(add_link_folder.png), the browser should open(browser.png)
    when the user single clicks on any file in the browser, it should go back to the (add_link_folder.png) and the location and name shud display the filepath and filename respectivly
    Attached Images Attached Images
    Last edited by kamlmish; 20th December 2010 at 10:55.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Get filepath and filename from qtreewidget

    You don't need to delete tree and model. They get deleted by Qt. Further what is the purpose of subclassing QTreeWidget and create a QTreeView inside? Also do you have seen QFileDialog?

    And where exactly crashes the program?

  3. #3
    Join Date
    Mar 2010
    Posts
    54
    Qt products
    Qt/Embedded
    Platforms
    Symbian S60

    Default Re: Get filepath and filename from qtreewidget

    1) I needed to display the filesystem , and therefore I used a QDirModel and QTreeView to display the filesystem
    The filesystem gets displayed in a new window(browser.png)
    2) QFileDialog would provide me a dialog box where I can select specific files and directories , but my objective is to display the filesystem in a tree view , select a specific file from the treeview , the selected file name and path would be displayed in a text browser

    The crash happens at
    connect(this,SIGNAL(clicked(QModelIndex)),SLOT(get Details(QModelIndex)),Qt:irectConnection);
    Last edited by kamlmish; 20th December 2010 at 09:06.

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Get filepath and filename from qtreewidget

    well within the posted code I don't see an error. Can you post the backtrace since it isn't (most likely) the connection statement.

Similar Threads

  1. QFileInfo::filePath and std::ofstream
    By TorAn in forum Qt Programming
    Replies: 1
    Last Post: 2nd December 2010, 00:55
  2. Filename -> directory
    By Persoontje in forum Newbie
    Replies: 2
    Last Post: 2nd December 2009, 22:54
  3. how to get filename
    By jayreddy in forum Qt Programming
    Replies: 1
    Last Post: 24th November 2009, 08:59
  4. pixmap filepath in property editor
    By purga in forum Qt Programming
    Replies: 1
    Last Post: 20th November 2009, 13:49
  5. Replies: 2
    Last Post: 8th April 2008, 10:35

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.