QDir::SetSorting Doesn't work on Ubuntu

两盒软妹~` 提交于 2019-12-08 12:18:47

问题


I have a problem with QDir, I have this folder with lots of images, and I need to iterate through them but, they have to be sorted, so, I'm using setSorting(QDir::Name) however, It doesn't work on Ubuntu. When I iterate it with QDirIterator it selects pictures in given folder randomly. The weird thing is I use the same exact code on Windows (minGW or MSVC) and It works perfectly.

someClass::someClass(QDir dir) {
     m_dir = dir;
     m_directory.setSorting(QDir::Name);
     QStringList filter;
     filter << QString("*.") + format << QString("*.") + "jpg";
     m_dir.setNameFilters(filter);
}
someClass::iterateDir() {
     QDirIterator it(m_dir);
     while(it.hasNext()) {
         it.next();
         qDebug() << it.fileName();

         //analayze the picture here
     }
}

here it.fileName() should print (0.jpeg, 1.jpeg .... 3000.jpeg) but instead it prints (2342.jpg, 1286.jpg, 684.jpg ... 712.jpg) I tried to use other sortFlags (QDir::Size, QDir::LocaleAware) but none of them works on Ubuntu. Is there something I'm missing? Thank you for your time.


回答1:


You are mixing 2 variables: m_dir and m_directory. I assume it's typo and you mean to use the same variable.

QDirIterator does not support sorting. QDir::setSorting() only affects the list returned by QDIr:: entryInfoList() and QDir:: entryList(). Use either of them for sorted iteration.



来源:https://stackoverflow.com/questions/12965919/qdirsetsorting-doesnt-work-on-ubuntu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!