Closing one QFileDialog also closes other QFileDialog on Windows
-
The following code creates a pops up three QFileDialog instances. Closing any of them (cancel or accept) will also close other dialogs. "finished()" signal gets emitted for all three dialogs. This happens on Windows only. The code works as expected on Linux. Qt version: 5.12.10.
main.cpp:
#include <QApplication>
#include <QFileDialog>
#include <QFontDialog>
#include <QDir>
#include <QDebug>
#include <vector>
#include "handler.hpp"int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QApplication::setQuitOnLastWindowClosed(false);
std::vector<QDialog*> dialogs;
MyHandler handler;for(int i = 0; i < 3; i++) { auto diag = new QFileDialog(nullptr, "Select Direcotry"); diag->setFileMode(QFileDialog::Directory); diag->setOptions(QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); diag->setWindowFlags(Qt::WindowStaysOnTopHint); diag->setDirectory(QDir::root()); dialogs.push_back(diag); QObject::connect(diag, &QFileDialog::finished, &handler, &MyHandler::finished_slot); diag->open(); diag->activateWindow(); diag->raise(); } return app.exec();
}
handler.hpp:
#ifndef HANDLER_HPP
#define HANDLER_HPP#include <QObject>
#include <QDebug>class MyHandler : public QObject
{
Q_OBJECTpublic slots:
void finished_slot(int result)
{
qDebug() << "sender: " << (qulonglong) sender() << " finished: " << result << " parent: " << sender()->parent();
}
};#endif
-
Hi
Yes, that does seem odd.
I could reproduce it here with Qt 5.15I have no good reason why all will close since the app is still running.
-
@tiantianxiangshang , @mrjj
I assume this behaviour would not happen if you setQFileDialog::DontUseNativeDialog
? I imagine the behaviour is linked to using the native Windows directory chooser dialog, rather than the Qt Windows code itself? -
@mrjj said in Closing one QFileDialog also closes other QFileDialog on Windows:
I assume it's due to the use of open not exec.
@tiantianxiangshang said in Closing one QFileDialog also closes other QFileDialog on Windows:
This happens on Windows only. The code works as expected on Linux.Strange then that would differ across platforms.
-
@tiantianxiangshang said in Closing one QFileDialog also closes other QFileDialog on Windows:
Does the behaviour change if you remove this unnecessary fluff?
diag->activateWindow(); diag->raise();
-
Using
QFileDialog::DontUseNativeDialog
solves the problem:
diag->setOptions(QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks | QFileDialog::DontUseNativeDialog);
Tested with Qt version 5.15.2 on Windows. Didn't test with version of Qt.@JonB said in Closing one QFileDialog also closes other QFileDialog on Windows:
@tiantianxiangshang , @mrjj
I assume this behaviour would not happen if you setQFileDialog::DontUseNativeDialog
? I imagine the behaviour is linked to using the native Windows directory chooser dialog, rather than the Qt Windows code itself?