Leetcode本地阅读器开发--01界面设计三

这篇文章主要写一下怎样实现定类别查找。

 1 void Widget::on_comboBox_currentIndexChanged(int index)
 2 {
 3     QString sortname;
 4     switch(index){
 5         case 1:  sortname="每日一题";   break;
 6         case 2:  sortname="";        break;
 7         default: break;
 8     }
 9     if(sortname=="")
10         return;
11     QDir dir;
12     dir.setPath(curPath);
13     if (!dir.exists()){
14         ui->textBrowser_3->clear();
15         ui->textBrowser_3->setText("dir error...");
16         ui->textBrowser_3->show();
17         return;
18     }
19     QList<QString> queue;
20     queList.clear();
21     queue.push_back(dir.path());
22     while(!queue.empty()){
23         dir.setPath(queue.front());
24         queue.pop_front();
25         dir.setFilter(QDir::Dirs|QDir::NoSymLinks|QDir::NoDotAndDotDot);
26         QFileInfoList list = dir.entryInfoList();
27         for(int i=0; i<list.size(); ++i){
28             QFileInfo fileinfo = list[i];
29             if(fileinfo.fileName()==sortname){
30                 dir.setPath(fileinfo.filePath());
31                 dir.setFilter(QDir::Files|QDir::NoSymLinks|QDir::NoDotAndDotDot);
32                 list = dir.entryInfoList();
33                 for(int j=0; j<list.size(); ++j){
34                     fileinfo = list[j];
35                     queList.push_back(fileinfo.filePath());
36                 }
37                 goto FINDOK;
38             }
39             else
40                 queue.push_back(fileinfo.filePath());
41         }
42     }
43     return;
44     FINDOK:
45     Showquelist();
46     Showque();
47 }

 

posted @ 2020-03-30 23:02  T丶jl  阅读(163)  评论(0编辑  收藏  举报