PDA

View Full Version : How to setRootPath to desktop for QFileSystemModel in Windows?



mismael85
29th November 2010, 11:41
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

BalaQT
29th November 2010, 13:31
hi the following will work

QFileSystemModel::setRootPath( "c:\\" )

hope it helps

Bala

wysota
29th November 2010, 13:40
Set the path to whatever QDesktopServices::storageLocation() returns for QDesktopServices::DesktopLocation.

mismael85
4th December 2010, 23:20
I did just as you said but still the application starts from the drivers path (on windows) not the desktop path

http://img843.imageshack.us/img843/8316/desktop0.png
I used the following code

m_pFileSystemModel = new QFileSystemModel;
QString dir = QDesktopServices::storageLocation(QDesktopServices ::DesktopLocation);
m_pFileSystemModel->setRootPath(dir);
ui->treeView->setModel(m_pFileSystemModel);
but i want it to be like this photo
http://img138.imageshack.us/img138/973/desktopsb.png

wysota
5th December 2010, 10:53
The problem is the second picture does not show the true model of the filesystem.

What does line #2 of your snippet return?

mismael85
5th December 2010, 16:17
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"

wysota
5th December 2010, 17:29
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.

ustccq
13th February 2014, 06:23
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.