Results 1 to 8 of 8

Thread: How to setRootPath to desktop for QFileSystemModel in Windows?

  1. #1
    Join Date
    Feb 2008
    Posts
    154
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default How to setRootPath to desktop for QFileSystemModel in Windows?

    Hi,
    I am trying to set the Root Path of the QFileSystemModel to the desktop on windows 7.
    but i don't know how to do this?
    i tried QFileSystemModel::setRootPath(QString("")) but did not work.
    can any body help?
    Thank you

  2. #2
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to setRootPath to desktop for QFileSystemModel in Windows?

    hi the following will work
    Qt Code:
    1. QFileSystemModel::setRootPath( "c:\\" )
    To copy to clipboard, switch view to plain text mode 

    hope it helps

    Bala

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to setRootPath to desktop for QFileSystemModel in Windows?

    Set the path to whatever QDesktopServices::storageLocation() returns for QDesktopServices::DesktopLocation.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    KillGabio (17th January 2013)

  5. #4
    Join Date
    Feb 2008
    Posts
    154
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to setRootPath to desktop for QFileSystemModel in Windows?

    I did just as you said but still the application starts from the drivers path (on windows) not the desktop path


    I used the following code
    Qt Code:
    1. m_pFileSystemModel = new QFileSystemModel;
    2. QString dir = QDesktopServices::storageLocation(QDesktopServices::DesktopLocation);
    3. m_pFileSystemModel->setRootPath(dir);
    4. ui->treeView->setModel(m_pFileSystemModel);
    To copy to clipboard, switch view to plain text mode 
    but i want it to be like this photo

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to setRootPath to desktop for QFileSystemModel in Windows?

    The problem is the second picture does not show the true model of the filesystem.

    What does line #2 of your snippet return?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #6
    Join Date
    Feb 2008
    Posts
    154
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to setRootPath to desktop for QFileSystemModel in Windows?

    the second picture is not Qt application it is a visual basic application and i want to make one like it with Qt.
    Line #2 returns "C:\Users\mismael\Desktop"

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to setRootPath to desktop for QFileSystemModel in Windows?

    Quote Originally Posted by mismael85 View Post
    the second picture is not Qt application
    I know. What I say is that it is not a model of your file system.

    Line #2 returns "C:\Users\mismael\Desktop"
    And when you set it as the root path of your model it still shows some other directory? Make sure you didn't make any mistakes (e.g. read the root path of the model back to see if it is set to the right location). Note - it will not make the dialog show things such as "libraries", "control panel" and stuff as they are artificial entities that are not part of the file system. If you want the exact same output, use native means to get it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #8
    Join Date
    Feb 2014
    Posts
    1
    Qt products
    Qt5

    Default Re: How to setRootPath to desktop for QFileSystemModel in Windows?

    have you done with this?
    recently i need my tree to run like the native CMFCShellTreeCtrl either.
    if you can mail any tips to my email: seak04#gmail.com will be graceful.

Similar Threads

  1. Accessing GPS device from qt desktop(windows) App
    By newtolinux in forum Qt Programming
    Replies: 7
    Last Post: 2nd November 2010, 20:05
  2. Locking and Unlocking Windows/Unix desktop
    By chrisjenx2001 in forum Qt Programming
    Replies: 1
    Last Post: 15th October 2010, 23:47
  3. Associate Program Icon for Windows Desktop
    By brent99 in forum Newbie
    Replies: 2
    Last Post: 11th March 2008, 04:22
  4. Draging a non-existing file to the Windows Desktop
    By klaus1111 in forum Qt Programming
    Replies: 13
    Last Post: 20th September 2007, 11:47
  5. Replies: 2
    Last Post: 30th August 2006, 10:09

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.