Solved QFileDialog Bug?
-
Hi @ModelTech,
can you show the code you use the create the dialog?
-
I hope this parts suffices. It is primarily the last line in this code to get the QFileDialog, but I also included the part where I create the Filter of allowed File Extensions
QStringList Extensions; QString Filters; for (int i = 0; i < Plugin->exportFileFilters().size(); ++i) { Filters += Plugin->exportFileFilters()[i]; if (i < Plugin->exportFileFilters().size()) Filters += ";;"; QStringList Splitted = Plugin->exportFileFilters()[i].split(QRegExp("\\(|,|\\)"), QString::SkipEmptyParts); for (int j = 1; j < Splitted.size(); ++j) if (Splitted[j].contains("*.")) Extensions.append(Splitted[j].trimmed().remove("*.")); } QString FileName = QFileDialog::getSaveFileName(this, tr("Export Model"), RecentLocation, Filters);
-
This has nothing to do with Qt (esp. since this is the native Windows file dialog) - it's the same for me with a non-Qt program on Windows 8.1 ...
-
Ah, it is windows 8 indeed on which I saw this. I can also try on other platforms.
Edit: And indeed, it's only on windows (also windows 10) but not on Linux. So, its a clear Microsoft bug... Thanks :)
-
@ModelTech
When using Windows or Linux file dialogs at least, the filename extension type is used to filter what is offered when loading/saving, and to provide a default extension if none specified when saving. However, they do not prevent the user typing in anything else he pleases regardless. -
@JonB : Yes, that's why I actually check what extension is eventually selected and if it is not what it should be, I add it. This is in the code right after the piece that I gave above. Thanks
-
This is no longer a Qt problem, but rather the operating system itself. Try doing the same thing with Paint, for example.
Look:
-
It's indeed only on windows (also windows 10) but not on Linux. So, its a clear Microsoft bug...
-
@ModelTech
It's not a bug. It's the way Windows chooses to implement the dropdown completer. They deliberately show existing files matching what you've typed regardless of extension, so that you know they exist. I quite like it. -
I perceived it as an inconsistency and I generally do not like inconsistencies too much ;)
-
@ModelTech
When you use http://doc.qt.io/qt-5/qfiledialog.html#getSaveFileName it takes a http://doc.qt.io/qt-5/qfiledialog.html#Option-enum parameter. Try passing itQFileDialog::DontUseNativeDialog
to get the Qt dialog instead of the native Windows one. See if that behaves differently/more as you like (it'll only take a second)?