먼저 여러 개의 이미지를 저장하는 폴더가 있다고 가정합니다. 그런 다음 UI에서 버튼을 클릭하여 폴더를 열고 그 폴더에있는 이미지의 모든 파일 경로를 QList (필터링 된 이미지 파일 만)에 저장하려고합니다. 그러나 QList는 아무 것도 저장하지 않습니다. 도와주세요.QT에서 QFileSystemModel에서 파일 경로를 얻는 방법 (C++)
의견에서 언급 한 바와 같이void MainWindow::on_pushButton_clicked()
{
QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
"/home",
QFileDialog::ShowDirsOnly
| QFileDialog::DontResolveSymlinks);
model = new QFileSystemModel();
filesPath = dir;
model->setRootPath(dir);
QStringList filter;
filter <<"*.png" <<"*.jpg" <<"*.bmp" <<"*.gif";
model->setNameFilters(filter);
model->setNameFilterDisables(false);
ui->treeView->setModel(model);
ui->treeView->setRootIndex(model->index(dir));
ui->treeView->setAnimated(false);
ui->treeView->setSortingEnabled(true);
QList<QString> path_list;
QModelIndex parentIndex = model->index(dir);
int numRows = model->rowCount(parentIndex);
for (int row = 0; row < numRows; ++row) {
QModelIndex childIndex = model->index(row, 0, parentIndex);
QString path = model->data(childIndex).toString();
if(!QFileInfo(path).isDir())
path_list.append(path);
}
}
Qt 문서를 읽어야합니다. http://doc.qt.io/qt-5/qfilesystemmodel.html#details –
@ md612 왜 QFileSystemModel을 사용하고 있습니까? –
@Dmitry Sazonov QtreeView – md612