PDA

View Full Version : i am unable to set path in QFileSystemModel



aurora
13th February 2012, 05:40
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....


QString sPath ="C:/Users/dmck/Desktop/folder1";

dirmodel =new QFileSystemModel(this);
dirmodel->setFilter(QDir::NoDotAndDotDot | QDir::AllDirs);
dirmodel->setRootPath(sPath);
ui->treeView->setModel(dirmodel);

ChrisW67
13th February 2012, 06:21
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.

aurora
13th February 2012, 06:36
Ok thank u...:)

wilsonbrant
27th March 2012, 08:29
does it work?why it cannot work in my program?

aurora
27th March 2012, 09:33
does it work?why it cannot work in my program?

Ya it worked perfectly for me.....

ChrisW67
28th March 2012, 07:43
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.