Results 1 to 6 of 6

Thread: i am unable to set path in QFileSystemModel

  1. #1
    Join Date
    Oct 2011
    Posts
    160
    Thanks
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default i am unable to set path in QFileSystemModel

    In my program i'm using tree view with a QFileSystemModel...
    But i'm unable to set a default root path in that.....
    i want to display a particular directory to display, whn program executes.....But it is showing c:\, d:\ and e:\ always...
    what should i do?


    code i tried.....But its not taking that path as default....

    Qt Code:
    1. QString sPath ="C:/Users/dmck/Desktop/folder1";
    2.  
    3. dirmodel =new QFileSystemModel(this);
    4. dirmodel->setFilter(QDir::NoDotAndDotDot | QDir::AllDirs);
    5. dirmodel->setRootPath(sPath);
    6. ui->treeView->setModel(dirmodel);
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,722
    Thanks
    13
    Thanked 1,606 Times in 1,533 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: i am unable to set path in QFileSystemModel

    setRootPath() doesn't do what you expect it does. You want to combine QFileSystemModel::index() and QTreeView::setRootIndex() to control what is in the view as described in the documentation.

  3. The following 2 users say thank you to ChrisW67 for this useful post:

    aurora (13th February 2012), iskenderoguz (8th January 2016)

  4. #3
    Join Date
    Oct 2011
    Posts
    160
    Thanks
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: i am unable to set path in QFileSystemModel

    Ok thank u...

  5. #4
    Join Date
    Mar 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: i am unable to set path in QFileSystemModel

    does it work?why it cannot work in my program?

  6. #5
    Join Date
    Oct 2011
    Posts
    160
    Thanks
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: i am unable to set path in QFileSystemModel

    Quote Originally Posted by wilsonbrant View Post
    does it work?why it cannot work in my program?
    Ya it worked perfectly for me.....

  7. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,722
    Thanks
    13
    Thanked 1,606 Times in 1,533 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: i am unable to set path in QFileSystemModel

    Quote Originally Posted by wilsonbrant View Post
    does it work?
    Yes.
    why it cannot work in my program?
    How are we supposed to know? ... It is not like we can read your code.

Similar Threads

  1. QFileSystemModel and QDirModel
    By lvlike in forum Qt Programming
    Replies: 1
    Last Post: 1st November 2011, 03:11
  2. QFileSystemModel with checkboxes...
    By been_1990 in forum Qt Programming
    Replies: 14
    Last Post: 11th March 2011, 15:01
  3. how use QFileSystemModel with QListView ?
    By lwifi in forum Qt Programming
    Replies: 4
    Last Post: 26th April 2010, 03:41
  4. Help with QFileSystemModel
    By TheShow in forum Qt Programming
    Replies: 4
    Last Post: 5th January 2010, 20:11
  5. Replies: 8
    Last Post: 17th October 2009, 08:10

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.