PDA

View Full Version : Problem in getting data using QFileSystemModel



chinmayapadhi
15th August 2010, 18:36
Hi ,

I am using QFileSystemModel to find the filenames, filesize, fileIcon and filePath of the files placed in C drive. So i used the QFileSystemModel.

The rowCount returns 0 and columnCount returns 4 .I dont understand the reason ? Please tell if there is anything that i can use to get the data apart from QFileSystemModel.
QFileSystemModel* fileModel = new QFileSystemModel;QModelIndex index = fileModel->setRootPath(QString("C:/"));
QString rootpath = fileModel->rootPath();
qDebug() << rootpath;
int rowCount = fileModel->rowCount();
int columnCount = fileModel->columnCount();

squidge
15th August 2010, 19:34
It probably hasn't completed by the time it reaches your "int rowCount = fileModel->rowCount();", as the calls are asynchronous.

You really shouldn't be using QFileSystemModel to just retrieve the contens of a directory. Have a look at classes such as QDir instead. QFileSystemModel is meant to be used as a MVC.