PDA

View Full Version : QFileDialog and file extension



calhal
28th November 2007, 20:23
Hi,
Anyone knows how can I force user to use my file extension? I'm using QFileDialog to ask user about file name. The filter is set to my own extension, but when I type name without extension, it is not included in path.
I've tried to check path string if it contains extension or not and then append it. But I'd like to do it inside QFileDialog, it checks if file exist and asks if user wants to replace it or not, so changing file name after this is not really good idea IMO.

wysota
28th November 2007, 20:49
If you can live without using the native file dialog (that's what happens when you use static versions of the dialog), you can create a QFileDialog subclass where you will reimplement accept() to make the checks and modifications yourself "inside" the dialog. If they are successful, call the base class implementation (QDialog::accept() would probably be better than QFileDialog::accept() here). Otherwise don't call the base class accept(), so the dialog doesn't get closed (or something like that). You can also create a helper method that will act in a fashion similar to what QFileDialog's static methods do (like return the list of files).

seyed
9th March 2010, 11:52
Hi,

I have same problem. Is this a bug for Qt's file dialog?
Qt must check and insert extension automatically.

wysota
9th March 2010, 13:54
Why would Qt insert the extension automatically (especially when you are using a native dialog)?


QString path = QFileDialog::getSaveFileName(...);
if(path.isEmpty()) return;
if(!path.endsWith(".ext"))
path.append(".ext");