Sorting directory entries with QDir

  • I am building a QFileInfoList from a directory and I want the list sorted by "Date created".
    QDir::Time uses the "Modified Date" and as far as I am aware there is no way to sort by "Date Created" using QDir. I can certainly use QFileInfo::created() and sort the list in code, but according to Qt documentation this will only work on Windows systems, apparently Linux returns "Modified Date" in most instances even when QFileInfo::created() is used. My application is multi-platform and I need to find a solution that works on both platforms. Any suggestions of how to handle this situation is most appreciated.

  • Moderators

    This is because (ordinarily) Linux doesn't keep a separate date for the creation of a file. There's no "date created" on most file systems that run on Linux, so naturally Qt, because it uses the available OS API, is unable to ascertain what is the creation time. You don't have much leeway but to use the modified time as a reference.
    Here you can read a bit more on the subject.

    Kind regards.

Log in to reply