Results 1 to 4 of 4

Thread: How display only /tmp dir with QFileSystemModel and QTreeView

  1. #1
    Join Date
    Jul 2010
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11 Maemo/MeeGo

    Default How display only /tmp dir with QFileSystemModel and QTreeView

    Hi
    Im having some problems with displaying a directory and its files in a QTreeView, im using QFileSystemModel and i keep getting a directory listing that looks like this

    /
    /tmp
    somefile
    +opt
    +root
    +sys
    someotherfile

    etc, etc, all i want to be displayed is the /tmp directory and its files. Im trying to make it so the user cant navigate anywhere else but the /tmp directoy. Here is the way im doing it now which keeps giving me all the files under /


    QString Location("/tmp/delete");
    m_FsModel = new QFileSystemModel();
    m_FsModel->setRootPath(Location);

    QDir* dir = new QDir(Location);
    m_FsModel->setRootPath(dir->path());
    m_FsModel->setReadOnly(true);

    thanks

  2. #2
    Join Date
    Jul 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How display only /tmp dir with QFileSystemModel and QTreeView

    You want only files and sub directories from /tmp/ listed? Then I wonder why you use
    Qt Code:
    1. QString Location("/tmp/delete");
    To copy to clipboard, switch view to plain text mode 
    as root path.
    Shoudn't it be
    Qt Code:
    1. String Location("/tmp/");
    To copy to clipboard, switch view to plain text mode 
    ?

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How display only /tmp dir with QFileSystemModel and QTreeView

    The docs for QFileSystemModel::setRootPath() contain this note:
    Note: This function does not change the structure of the model or modify the data available to views. In other words, the "root" of the model is not changed to include only files and directories within the directory specified by newPath in the file system.
    Emphasis mine. You probably want to look up the model index corresponding to "/tmp" and call QTreeView::setRootIndex()
    Qt Code:
    1. QFileSystemModel *m_FsModel = new QFileSystemModel();
    2. m_FsModel->setRootPath("/tmp");
    3.  
    4. v.setModel(m_FsModel);
    5. QModelIndex idx = m_FsModel->index("/tmp");
    6. v.setRootIndex(idx);
    7. v.show();
    To copy to clipboard, switch view to plain text mode 
    Last edited by ChrisW67; 18th July 2010 at 23:41. Reason: Added code example

  4. The following user says thank you to ChrisW67 for this useful post:

    saa7_go (19th July 2010)

  5. #4
    Join Date
    Jul 2010
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11 Maemo/MeeGo

    Default Re: How display only /tmp dir with QFileSystemModel and QTreeView

    That was perfect thanks!

Similar Threads

  1. QTreeView display of graph (multiple parents of item)
    By iraytrace in forum Qt Programming
    Replies: 12
    Last Post: 16th May 2014, 19:34
  2. how to display QSqlQueryModel in QTreeView
    By mandal in forum Newbie
    Replies: 6
    Last Post: 2nd September 2009, 08:25
  3. Process the display data before displaying in QTreeView
    By babu198649 in forum Qt Programming
    Replies: 5
    Last Post: 23rd June 2009, 05:21
  4. Display data from QStandardItemModel in QTreeView
    By jprice01801 in forum Qt Programming
    Replies: 7
    Last Post: 10th January 2007, 09:34
  5. Can't change the text display of a QTreeview item.
    By johnny_sparx in forum Qt Programming
    Replies: 3
    Last Post: 2nd June 2006, 01:03

Tags for this Thread

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.