每当我在我的 QFileDialog 中选择一个文件时,accepted
信号就会被触发并且窗口会关闭。我想让窗口保持打开状态,这样我就可以选择多个文件,然后捕获单击“打开”时触发的信号。
QFileDialog* myDialog = new QFileDialog(this);
myDialog->setFileMode(QFileDialog::ExistingFiles);
myDialog->setVisible(true);
我应该在这里连接什么信号才能达到这种效果?
最佳答案
QFileDialog::ExistingFiles
应该保证可以选择多个文件。鉴于此,您可以连接到信号:
void QFileDialog::filesSelected(const QStringList & selected)
直接来自文档:
When the selection changes for local operations and the dialog is accepted, this signal is emitted with the (possibly empty) list of selected files.
但是,如果您只对收集此类文件感兴趣,则完全可以避免信号槽并编写(再次从文档中获取):
QStringList fileNames;
if (dialog.exec())
fileNames = dialog.selectedFiles();
请注意,在这种情况下,dialog
对象已在堆栈上创建(这是此类对象的常用方法)。
关于c++ - 仅在单击 "open"时关闭 QFileDialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26352596/