在QDir::entryInfoList中使用多个条件进行排序

Sorting with multiple conditions in QDir::entryInfoList

本文关键字:条件 排序 QDir entryInfoList      更新时间:2023-10-16

Qt的文档说QDir::entryInfoList可以接受多种排序条件,但我不清楚如何做到。

This enum describes the sort options available to QDir, e.g. for entryList() and entryInfoList(). 
The sort value is specified by OR-ing together values from the following list: 
QDir::Name  0x00    Sort by name.
QDir::Time  0x01    Sort by time (modification time).
:
(snip)

我想OR-ing需要以某种方式完成。现在我想不出该怎么做(我想必须回去复习一下?)但有人能告诉我怎么做吗?非常感谢。

(无论如何,作为高级语言的文档,这个描述并不清楚?)

QDir::SortFlags实际上是QFlags<QDir::SortFlag>的typedef,是存储枚举值OR组合的类型安全方式。

因此,在您的案例中,您所做的只是将QDir::Name | QDir::Time作为QDir::entryInfoList()方法的自变量。