PDA

View Full Version : QFileDialog 'Save As' to non-existent directory



mclark
9th September 2010, 22:37
Qt: 4.6.2 Commercial
Windows XP

My app is a configuration tool. When a user has setup things to their satisfaction they are to save the configuration to disk. The problem is that the configuration is actually a group of files. To the user I must make a directory (and its contents) look like the configuration (a single entity).

Using QFileDialog I can view the directory where the configurations are to be stored (Configs in the example below).

My problem is getting QFileDialog to allow me to save. If the destination directory exists (the 'Save' case) this is not a problem. But, if the user wants to do 'Save As' the QFileDialog will disable the Save button as soon as a non-existing directory name is typed.

Directory Structure Example:

+--Configs
| |
| +--Configuration_1
| | |
| | +--<actual configuration files>
| |
| +--Configuration_2
| | |
| | +--<actual configuration files>

I need to be able to type in a directory name (ex. Configuration_3) and have the Save button enabled so when the QFileDialog exits I can handle all the actual directory and file creation.

Is what I'm trying to do possible using QFileDialog?


QFileDialog fileDlg( this );
fileDlg.setWindowTitle( sDlgTitle );
fileDlg.setDirectory( sConfigPath );
fileDlg.setFileMode( QFileDialog::DirectoryOnly );
fileDlg.setOptions( QFileDialog::ShowDirsOnly );
fileDlg.setAcceptMode( QFileDialog::AcceptSave );

if ( fileDlg.exec() == QDialog::Rejected )
return;

QString sConfigPath = (fileDlg.selectedFiles())[0];

wysota
9th September 2010, 22:59
Why don't you ask for files then? Set file mode to AnyFile, show only directories (as you do now) and when the "file name" is returned, make it a directory.

mclark
9th September 2010, 23:32
:oYes, of course. Can't believe I missed that.

Thank you for the prompt and problem-solving reply.