views:

348

answers:

2

I'm trying to simply save a file. However, I need a filename entered without a suffix to automatically get a default suffix (which setDefaultSuffix() does).

I'd rather not completely lose the native save dialog just for this. exec() is not overloaded from QDialog, so it totally bypasses the native hook (ignoring the DontUseNativeDialog option even if it's false).

If I disable the file overwrite warning and append the default suffix myself after the function returns, then I'd be re-opening the dialog if the user did not want to overwrite... and that's just ugly.

Is there some signal I can catch and quickly inject the default suffix if it's not there? I'm guessing not, since it's a native dialog.

Is there something I'm doing wrong with the filter? I only have one filter choice. It should use that extension.

This seems pretty lame. Launching the save dialog and simply typing "test" should never result in an extensionless file. "test.", yes. "test" no way. That'll really confuse the users when they hit Load and can't see the file they just saved.

I guess the cross-platform part of Qt is giving me lowest common denominator file dialog functionality?

A: 

Have you tried the filter options in the static functions? [Edit: Oops, noticed that you already have.]

I just tried this myself, for example, and things seem to be fairly reasonable:

QString filter = "Text files (*.txt)";
QString selectedFilter;
QString filename = QFileDialog::getSaveFileName(0, "", "", filter, &selectedFilter);

Entering test in the save dialog returns test.txt.
Entering test. in the save dialog returns test..txt.
Entering test.foo in the save dialog returns test.foo.

These all show the appropriate overwrite dialog if there is already an existing file with that name.

The only way I can get test, without any suffixes, is by surrounding it with quotes ("test"), or by first entering *.* (which will make it display all files) and then entering test. (Although one oddity is that selectedFilter will still contain the filter shown in the dialog, even if it's not used).

richardwb
Maybe it's a platform thing. My native dialog is GTK (GNOME/Linux), what's yours?
darron
Mine is Windows. Guess that's probably where the difference lies.
richardwb
A: 

Yes, if you look at the Qt source code it is evident that only the static functions uses native file dialogs. It is not possible to get native dialogs any other way, unfortunately...

Mathias