QDir::entryList() sorts files when QDir::NoSort flag is set

75 Views Asked by At

I have a local directory where some images are stored. The images are named like "1.JPG", "2.JPG", "3.JPG", etc. When i view them through explorer, they are sorted ascending int value in name, i.e "1.JPG" is first, "2.jpg" is second, "3.JPG" is third, etc.

Now i want to upload all file names from that directory to QStringList in my application. It's done like so:

QDir directory(imageDirectory);
imagesToMerge = directory.entryList(QStringList() << "*.jpg" << "*.JPG", QDir::Files);

where imagesToMerge is a QStringList, which i want to contain all the filenames;

The problem is that when i view this list (using qDebug(), for example), filenames are sorted by name, i.e if i have 20 images ("1.JPG" to "20.JPG"), they will be sorted like so:

  1. "1.JPG"
  2. "10.JPG"
  3. "11.JPG"

    ...

    1. "9.JPG"

This is not the behaviour i want.

I tried setting QDir::NoSort flag in QDir::entryList(), but it made no impact.

Is there a way to make this function behave the way i want? If not, is there any alternative way?

Thanks in advance!

0

There are 0 best solutions below