1.文件夹对话框
QString directory = QFileDialog::getExistingDirectory(this,"select dir","",QFileDialog::ShowDirsOnly); if (!directory.isEmpty()) {
......
}
2.文件对话框
//括号里的参数分别是:指定父类、标题、默认打开后显示的目录、右下角的文件过滤器。 QString file_name = QFileDialog::getOpenFileName(NULL,"标题",".","*.txt");
qDebug() << file_name;
3.遍历文件下所有文件
QStringList getFileNames(const QString &path) { QDir dir(path); QStringList nameFilters; nameFilters << "*.jpg" << "*.png" << "*.bmp"; QStringList files = dir.entryList(nameFilters, QDir::Files|QDir::Readable, QDir::Name); return files; }