Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QFileDialog and Filters
What is the defined behaviour of QFileDialog if the user has called setNameFilters() with a set of filters, but has not called selectNameFilter()?
If this were the Windows CFileDialog, the behaviour in this case is determined by the value of nFilterIndex in the OPENFILENAME struct:
The index of the currently selected filter in the File Types control. The buffer pointed to by lpstrFilter contains pairs of strings that define the filters. The first pair of strings has an index value of 1, the second pair 2, and so on. An index of zero indicates the custom filter specified by lpstrCustomFilter. You can specify an index on input to indicate the initial filter description and filter pattern for the dialog box. When the user selects a file, nFilterIndex returns the index of the currently displayed filter. If nFilterIndex is zero and lpstrCustomFilter is NULL, the system uses the first filter in the lpstrFilter buffer. If all three members are zero or NULL, the system does not use any filters and does not show any files in the file list control of the dialog box.
Simply look at the source code :)
Actually what I really want to know is what it is supposed to do in this scenario for all operating systems.
I know that on Windows, if the user hasn't selected the filter, it will use the first filter that the user has defined, is that consistently true for all systems?
is that consistently true for all systems?
You have to ask the OS vendors I would guess (or better the window-manager vendors)
I'm asking about the behaviour of QFileDailog so the question belongs here IMHO.
@Perdrix Then take a look at the sources.
JonB last edited by JonB
The usual rule is: if the Qt docs do not state explicitly what such-and-such a behaviour is, then there isn't a "defined/guaranteed" behaviour. Else the docs would have said so!
People then look at the source code if they want to know what is really going on. And you're welcome to do that. It quite possibly will not change from however you see it now, but that is not a promise, so you act on it at your own risk.