0

I'm constructing a QDirIterator with a specific directory. The files inside look like this:

file_0
files_1
file_2
.
.
.
.

if I use Windows, the iteration is normal, but if I use Linux, the order is different:

file_0
file_1
file_10
file_100
.
.
.
file_2
file_20
.
.

This is the code:

while(it.hasNext()) {
    QString tmp = it.next();
}

I need the Windows type of iteration. How can I control that? How come it works differently in different operating systems (cross-platform)?

jkdev
  • 11,360
  • 15
  • 54
  • 77
asaf anter
  • 71
  • 2
  • 11
  • 2
    Possible duplicate of [QDir::SetSorting Doesn't work on Ubuntu](https://stackoverflow.com/questions/12965919/qdirsetsorting-doesnt-work-on-ubuntu) – Mohammad Kanan Jul 02 '18 at 16:19

1 Answers1

0

It's still cross platform, and does exactly what it claims to do. Which is iterate over entries in a directory.

You're expecting sorted results, which isn't part of the specified behavior. The difference is likely because the file systems are different (NTFS vs EXT3/4), and organize the underlying inodes in different ways.

If you want standardized behavior you can follow Mohammad's link in the comment or sort them yourself by throwing them into a QStringList and calling sort.