0

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!

George
  • 578
  • 4
  • 21
  • 3
    You can't rely on the order of the files when you set the `QDir::NoSort` flag, they are returned in whatever order the OS have chosen to follow. If you want a specific order, you need to apply your own sorting function at some point... – Mike Dec 16 '19 at 12:06
  • @Mike thank you for clarification, now application behaves the way i want – George Dec 16 '19 at 12:13

0 Answers0