zoukankan      html  css  js  c++  java
  • QT中检索设定目录下所有指定文件的方法

    void MainWindow::on_pushButton_clicked()
    {
        QDir dir=QFileDialog::getExistingDirectory(this, tr("Open Directory"),
                                                   "",
                                                   QFileDialog::ShowDirsOnly
                                                   | QFileDialog::DontResolveSymlinks);
    
        QStringList nameFilters;
        nameFilters << "*.c" << "*.h";
        QDirIterator dirIterator(dir.path(), nameFilters, QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
        QStringList fileName;
        while(dirIterator.hasNext())
        {
            fileName << dirIterator.fileName();
            dirIterator.next();
        }
        if(fileName.empty())
            return;
        fileName.removeFirst();
        ui->tableWidget->setColumnCount(2);
        ui->tableWidget->setRowCount(fileName.size());
    
        QStringList headers;
        headers << QStringLiteral("文件") << QStringLiteral("类型");
        ui->tableWidget->setHorizontalHeaderLabels(headers);
        for(int i=0;i<fileName.size();i++)
            ui->tableWidget->setItem(i,0,new QTableWidgetItem(iconText,fileName[i]));
    
    
    }
    

      

  • 相关阅读:
    LeetCode.152
    python
    python
    python
    python
    python
    python
    python
    PyCharm2020.1激活码破解教程
    Python GUI编程(Tkinter)17、Menu鼠标右键菜单
  • 原文地址:https://www.cnblogs.com/WeyneChen/p/5293123.html
Copyright © 2011-2022 走看看