qt - 检查目录是否为空

标签 qt qt4

我正在尝试检查目录是否为空。

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QDir Dir("/home/highlander/Desktop/dir");
    if(Dir.count() == 0)
    {
        QMessageBox::information(this,"Directory is empty","Empty!!!");
    }
}

检查它的正确方法是什么,不包括 ... ?

最佳答案

好吧,我有办法做到这一点:)

if(QDir("/home/highlander/Desktop/dir").entryInfoList(QDir::NoDotAndDotDot|QDir::AllEntries).count() == 0)
{
    QMessageBox::information(this,"Directory is empty","Empty!!!");
}

关于qt - 检查目录是否为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16351699/

相关文章:

c++ - 未知模块 QT : webkit

c++ - 在 aux 方法中创建的 QWidget 不显示/绘制

c++ - 我如何检测我的局域网连接是否在 C++ 中关闭/打开

python - pyqt - 将颜色与现有数据一起放入 QTableView 中

qt - 在没有GUI的情况下获取字体指标(控制台模式)

ruby - 如何打包 Ruby 应用程序?

c++ - QScript 的问题

c++ - Qt4/C++/CMake - 没有合适的默认构造函数可用

qt - 如何在 QT OpenGL Widget 上使用 OpenGL 函数?

c++ - QT 4.8 中的几个监视器全屏应用程序