Sort function in Qdir
-
I set the directory to come first by using the setSorting function.
I'm getting the path information with QDirIterator, but it doesn't get it in the way I want it to be sorted. Import files in the middle.Is there any way to get the directory first?
void wMethodInfo::UpdateCurrentPathInfo(QString strPath) { QDir rootPath(strPath); rootPath.setFilter(QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs); rootPath.setSorting(QDir::SortFlag::DirsFirst); QDirIterator it(rootPath, QDirIterator::FollowSymlinks); while (it.hasNext()) { it.next(); const QFileInfo& fInfo = it.fileInfo(); //qDebug() << "File Name(): " << it.fileName(); //qDebug() << "PopulateFileToSizeHash(): " << it.fileInfo(); //qDebug() << "PopulateFileToSizeHash(): " << it.filePath(); //if (fInfo.isFile()) //qDebug() << "PopulateFileToSizeHash(): " << it.filePath(); AddItem(fInfo.fileName()); } }
-
@IknowQT said in Sort function in Qdir:
I'm getting the path information with QDirIterator, but it doesn't get it in the way I want it to be sorted. Import files in the middle
As you can see in documentation,
QDirIterator
is not able to sort (cf. https://doc.qt.io/qt-5/qdiriterator.html#QDirIterator).So if sorting is something important for you, than you should better use
QDir::entryList()
orQDir::entryInfoList()
-
@IknowQT said in Sort function in Qdir:
I'm getting the path information with QDirIterator, but it doesn't get it in the way I want it to be sorted. Import files in the middle
As you can see in documentation,
QDirIterator
is not able to sort (cf. https://doc.qt.io/qt-5/qdiriterator.html#QDirIterator).So if sorting is something important for you, than you should better use
QDir::entryList()
orQDir::entryInfoList()
-
This post is deleted!
-
[EDIT: Post moved from other thread --JKSH]
I have one additional inquiries if itβs not too much trouble ππ, guide me about this. These inquiries are displayed underneath here:
https://forum.qt.io/topic/135772/sort-function-in-qdir
Sitting tight for most appropriate response straightaway. Iβm excessively confounded here π¨π¨.
-
[EDIT: Post moved from other thread --JKSH]
@zalteyitro
HI. This thread has no connection to the one you link to. If you want to ask a question in that thread please go there and do so, or open your own thread and reference that one from it.