PDA

View Full Version : how use QFileSystemModel with QListView ?



lwifi
12th April 2010, 17:57
Hi friends,
i use Qt jambi with eclipse and i have a small problem with QFileSystemModel ..... this model doesn't show me what i want exactly

i just want to know how QFileSystemModel work to obtain this result

went i select a folder in left side ( QTreeView ) i obtain the content of this folder in the right side ( in QListView )

please help me ........:confused:

http://img388.imageshack.us/img388/8519/fff.png

thanks

lwifi
13th April 2010, 20:48
Hi, again
here what i do to obtain a folder path


public String selected_file(QModelIndex i)
{
String paren,child; //put the final path in child

QAbstractItemModel mdir = ui.treeView.model();
Object dt = mdir.data(i);
QModelIndex par = mdir.parent(i);

child = dt.toString();
while(par != null)
{
paren = par.data().toString();
child = paren +"/"+ child;
par = par.parent();
}
return child;
}


so, i want to show the files of this path in QListView with QFileSystemModel
but i don't know how this model works !!!!!


public void show_file(String path)
{

QFileSystemModel std = new QFileSystemModel();
QDir dir = new QDir(path);
std.setRootPath(dir.path());

ui.listView.setUniformItemSizes(true);
ui.listView.setModel(std);

}

but this function doesn't works °° :confused:
thanks ...

lwifi
16th April 2010, 13:26
any thing ???

lwifi
17th April 2010, 18:18
Hi again :)
i found the solution of this bug
this's a part of code to display the content of a folder


public void show_file(String Path)
{
//initialization of fileSystem Model and Dir path
QFileSystemModel std = new QFileSystemModel();
QDir dir = new QDir(path);

// to arrange the items
ui.listView.setUniformItemSizes(true);

// join the model to the listView
ui.listView.setModel(std);
ui.listView.setRootPath(std.index(dir.path()));

}


Have a good time ;)

Antebios
26th April 2010, 03:41
Line 12 of the code above: "setRootPath" is not a method of QListView, but a method of the QFileSystemModel. Can you please correct that line?