Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 124
Registered: ‎01-29-2011
My Device: Z10, PlayBook
My Carrier: Koodo

QDir/QDirIterator not reading all files in directory on SD card

Has anyone seen this issue before? I'm using QDirIterator to get a list of files in a directory on the SD card, but it's missing most of them. There are 30 files, and QDirIterator only gives me 3.

 

If I load the directory into a QDir object, QDir::count() tells me there are five items in the directory (it's including '.' and '..').

 

A friend is running this for me on a device, and he assures me the files all have the same permissions. I can't reproduce the problem on the simulator.

 

I've written some debug code that uses opendir() and readdir() to do the directory listing, but now I have to wait for my friend to have a chance to run it and email the log output back... Debugging is definitely slower when you don't have direct access to a dev alpha. Smiley Sad

Highlighted
Developer
Posts: 671
Registered: ‎03-21-2012
My Device: BlackBerry PlayBook 16GB
My Carrier: Vip

Re: QDir/QDirIterator not reading all files in directory on SD card

This sample is from Qt docs and should help you a bit

 

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;
 }

 

Developer
Posts: 124
Registered: ‎01-29-2011
My Device: Z10, PlayBook
My Carrier: Koodo

Re: QDir/QDirIterator not reading all files in directory on SD card

Thanks, but iterating over directories is not a problem. As I mentioned, there are 30 files in the directory, and QDir::count() returns 3 (after subtracting 2 for "." and ".."). The built in directories on the phone are fine, and everything works fine on the simulator.

 

My friend got back to me with results from the last test, and even using the stdlib functions (opendir() and readdir()) don't work for listing any but the same three files. It's bizarre -- all have exactly the same permissions:

-rw-rw----   1 root      1000_shared

 

Anyway, he copied everything over to a different SD card and now it's fine. Very strange.

Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: QDir/QDirIterator not reading all files in directory on SD card