我有:
QFileDialog file_dialog;
file_dialog.setFileMode(QFileDialog::Directory);
QStringList selected_directory;
selected_directory << file_dialog.getExistingDirectory();
但我看不到任何文件。有没有办法看到他们能够只选择目录?
答案 0 :(得分:0)
当您呼叫getExistingDirectory
时,ShowDirsOnly
标志已设置
QString dir = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
"/home",
QFileDialog::ShowDirsOnly
| QFileDialog::DontResolveSymlinks);
请改用以下内容:
QFileDialog dialog(this);
dialog.setFileMode(QFileDialog::Directory);
QStringList dirNames;
if (dialog.exec())
dirNames = dialog.selectedFiles();
可以从dirNames
字符串列表中检索所选目录。