QDir :: SetSorting在Ubuntu上不起作用 [英] QDir::SetSorting Doesn't work on Ubuntu
问题描述
我对QDir有问题,我的文件夹中包含很多图像,我需要遍历它们,但是必须对其进行排序,因此,我使用的是 setSorting(QDir: :名称)
,但是在 Ubuntu 上不起作用。当我使用QDirIterator对其进行迭代时,它会随机选择给定文件夹中的图片。奇怪的是,我在Windows(minGW或MSVC)上使用了完全相同的代码,并且运行良好。
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
}
}
此处 it.fileName()
应该打印(0.jpeg,1.jpeg .... 3000.jpeg),但会打印(2342.jpg,1286 .jpg,684.jpg ... 712.jpg)我尝试使用其他 sortFlags
( QDir :: Size,QDir :: LocaleAware
),但它们都无法在Ubuntu上运行。
我缺少什么吗?
谢谢您的时间。
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.
推荐答案
您正在混合2个变量: m_dir
和 m_directory
。我认为这是拼写错误,您的意思是使用相同的变量。
You are mixing 2 variables: m_dir
and m_directory
. I assume it's typo and you mean to use the same variable.
QDirIterator
不支持排序。 QDir :: setSorting()
仅影响 QDIr :: entryInfoList()
和 QDir :: entryList()
。将它们之一用于排序迭代。
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.
这篇关于QDir :: SetSorting在Ubuntu上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!