PDA

View Full Version : How to create root node inQDirModel



deepak
29th August 2012, 06:12
Hello all,
I want to create the tree representation of the selected directory in my file system. Currently below code is used for this:

QDirModel model;
model.setFilter(QDir::Dirs | QDir::Files);
QTreeView tree_view;
tree_view.setModel(&model);
tree_view.setRootIndex(model.index("c:\myFiles"));
tree_view.show();

But problem with this code is that, it is not showing the selected directory as a root node. Instead, it only shows the files (and directories) presented in c:\myFiles directory. i.e. i want to view my tree structure as below

myFiles
│-- A.vbs
│-- B.log
│-- C.log
│
└───Test
│-- Y.log
â””-- X.vbs


But i am getting the below populated structure (without root element).

-- A.vbs
-- B.log
-- C.log
└───Test
│-- Y.log
â””-- X.vbs

Also i want to create tree structure of two independent folders in a single tree view in the later course of actions.
Kindly help.

Ginsengelf
29th August 2012, 07:03
Hi, does the root node show up when you don't set filters?
And maybe you want to use QFileSystemModel, because its performance is better than QDirModel.

Ginsengelf