在我的代码中,我列出了子目录名称(只有子目录),如果我单击此子目录,将显示此子目录中的图像。就我而言,我无法从 lambda 内部捕获父目录。我怎样才能做到这一点?
Dir directory = QFileDialog::getExistingDirectory(this, tr("Open Directory"),"/home",
QFileDialog::ShowDirsOnly| QFileDialog::DontResolveSymlinks);
for (const QFileInfo &finfo: directory.entryInfoList()) {
QDir dir(finfo.absoluteFilePath());
ui->listWidget_dirs->addItem(dir.dirName());
}
//QStringList files = directory.entryList(QDir::Dirs);
//ui->listWidget_dirs->addItems(files);
auto listWidget_images = new QListWidget();//set listwidget to display images
listWidget_images->setMinimumSize(1200,400);
listWidget_images->setViewMode(QListWidget::IconMode);
listWidget_images->setIconSize(QSize(320,240));
listWidget_images->setResizeMode(QListWidget::Adjust);
connect(ui->listWidget_dirs, & QListWidget::itemClicked,[listWidget_images,this](QListWidgetItem *item)
{
listWidget_images->show();
listWidget_images->clear();
/*this is where it is wrong*/ QDir path(directory + '/' + item->text());
path.setNameFilters({"*.png", "*.jpg"});
for(const QFileInfo & finfo: path.entryInfoList()){
QListWidgetItem *item = new QListWidgetItem(QIcon(finfo.absoluteFilePath()), finfo.fileName());
listWidget_images->addItem(item);
}
});