PDA

View Full Version : Display files of a Directory



mansu
8th March 2009, 11:07
hi to everyone,
i'm a newbie of programming Qt (using 4.4.3 on a Unix system) .....can anyone tell me the easy way to display Files of a specific dir?
i search on the forum but i readed something about QDir and QTreeView but i don't find anything reguarding them

An example will be very appreciated.

Thanks to everyone

arturo182
8th March 2009, 11:32
There's an example in QDir Class Reference:


A program that lists all the files in the current directory (excluding symbolic links), sorted by size, smallest first:


#include <QDir>
#include <iostream>

int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
QDir dir;
dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
dir.setSorting(QDir::Size | QDir::Reversed);

QFileInfoList list = dir.entryInfoList();
std::cout << " Bytes Filename" << std::endl;
for (int i = 0; i < list.size(); ++i) {
QFileInfo fileInfo = list.at(i);
std::cout << qPrintable(QString("%1 %2").arg(fileInfo.size(), 10)
.arg(fileInfo.fileName()));
std::cout << std::endl;
}
return 0;
}

faldzip
8th March 2009, 15:08
Look at the Directory View (http://doc.trolltech.com/4.4/itemviews-dirview.html) example. It uses QDirModel. The simplest way would be:


QTreeView * treeView = new QTreeView(this);
QDirModel * dirModel = new QDirModel(this);
treeView->setModel(dirModel);