Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QDir::entryInfoList unexpected behavior

Tags:

c++

qt4

My code is pretty simple:

void DirManagement::listFiles(QDir dir)
{
   QFileInfoList list = dir.entryInfoList(QDir::NoFilter, QDir::NoSort);
   for (int i = 0; i < list.size(); ++i)
   {
      QFileInfo fInfo = list.at(i);
      QString fPath = fInfo.absoluteFilePath();
      qDebug() << "# " << i << fPath;   }
}

The problem is that, if my directory path is: "/home/adasi/Desktop/GCUFolder" this is the result:

#  0 "/home/Alya/Desktop/MCUFolder" 
#  1 "/home/Alya/Desktop" 
#  2 "/home/Alya/Desktop/MCUFolder/32Mon Oct 24 2011" 
#  3 "/home/Alya/Desktop/MCUFolder/32Sun Oct 23 2011"

However, What I am expecting is ONLY whats under the given directory:

#  0 "/home/Alya/Desktop/MCUFolder/32Mon Oct 24 2011" 
#  1 "/home/Alya/Desktop/MCUFolder/32Sun Oct 23 2011"

I tried most of the qt filters. Didn't work.

like image 281
user1009532 Avatar asked Dec 28 '22 12:12

user1009532


1 Answers

Just to add more information It worked like Mat said, specifying what you want to list, like this:

myQdirObject.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::NoSort);
like image 104
fredcrs Avatar answered Jan 17 '23 16:01

fredcrs