久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用 Qt 自然地對文件名進(jìn)行排序

Sort filenames naturally with Qt(使用 Qt 自然地對文件名進(jìn)行排序)
本文介紹了使用 Qt 自然地對文件名進(jìn)行排序的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我正在使用 QDir::entryList() 讀取目錄內(nèi)容.里面的文件名結(jié)構(gòu)如下:

I am reading a directories content using QDir::entryList(). The filenames within are structured like this:

index_randomNumber.png

我需要按 index 對它們進(jìn)行排序,Windows 資源管理器對文件進(jìn)行排序的方式,以便我獲得

I need them sorted by index, the way the Windows Explorer would sort the files so that I get

0_0815.png
1_4711.png
2_2063.png
...

而不是按 QDir::Name 排序給我的:

instead of what the sorting by QDir::Name gives me:

0_0815.png
10000_6661.png
10001_7401.png
...

Qt 中是否有內(nèi)置的方法來實現(xiàn)這一點,如果沒有,在什么地方實現(xiàn)它?

Is there a built-in way in Qt to achieve this and if not, what's the right place to implement it?

推薦答案

如果你想使用 QCollat??orQDir::entryList,你可以用 std::sort():

If you want to use QCollator to sort entries from the list of entries returned by QDir::entryList, you can sort the result with std::sort():

dir.setFilter(QDir::Files | QDir::NoSymLinks);
dir.setSorting(QDir::NoSort);  // will sort manually with std::sort

auto entryList = dir.entryList();

QCollator collator;
collator.setNumericMode(true);

std::sort(
    entryList.begin(),
    entryList.end(),
    [&](const QString &file1, const QString &file2)
    {
        return collator.compare(file1, file2) < 0;
    });


根據(jù)The Badger的評論,QCollat??or也可以直接使用作為 std::sort 的參數(shù),替換 lambda,因此對 std::sort 的調(diào)用變?yōu)?


According to The Badger's comment, QCollator can also be used directly as an argument to std::sort, replacing the lambda, so the call to std::sort becomes:

std::sort(entryList.begin(), entryList.end(), collator);

這篇關(guān)于使用 Qt 自然地對文件名進(jìn)行排序的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數(shù)據(jù)?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環(huán): for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環(huán)?)
Reusing thread in loop c++(在循環(huán) C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環(huán)形?)
主站蜘蛛池模板: 福利视频一区二区 | 国产91丝袜在线播放 | 日韩视频第一页 | 久久99精品久久久久久国产越南 | 性欧美精品| 日韩视频免费大全中文字幕 | 五月天婷婷网站 | 在线免费看a | 亚洲精品1区2区 | 成人免费毛片男人用品 | 国产精品欧美日韩 | 国产精品久免费的黄网站 | 一级片网址 | 亚洲不卡 | 欧美精品系列 | 欧美成人一级 | 久久精品在线观看 | 亚洲 欧美 激情 另类 校园 | 五月av| 天天操操操 | 欧美不卡一区二区三区 | 欧美成人免费视频 | 午夜精品视频 | 毛片毛片毛片毛片毛片 | 中文字幕日韩一区 | 俺去俺来也在线www色官网 | 日狠狠| 欧美日韩国产一区二区三区 | 国产一级在线视频 | 日韩欧美中文字幕在线观看 | 九九精品视频在线观看 | 国产精品99久久久久久久久 | 成人欧美一区二区三区白人 | 福利片在线观看 | 99热最新 | 国产精品免费一区二区三区 | 久久少妇 | 干干干操操操 | 中文字幕在线观看免费视频 | 国产成人综合网 | 欧美日韩一二区 |