Results 1 to 3 of 3

Thread: QFileDialog 'Save As' to non-existent directory

  1. #1
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Thanks
    35
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question QFileDialog 'Save As' to non-existent directory

    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?

    Qt Code:
    1. QFileDialog fileDlg( this );
    2. fileDlg.setWindowTitle( sDlgTitle );
    3. fileDlg.setDirectory( sConfigPath );
    4. fileDlg.setFileMode( QFileDialog::DirectoryOnly );
    5. fileDlg.setOptions( QFileDialog::ShowDirsOnly );
    6. fileDlg.setAcceptMode( QFileDialog::AcceptSave );
    7.  
    8. if ( fileDlg.exec() == QDialog::Rejected )
    9. return;
    10.  
    11. QString sConfigPath = (fileDlg.selectedFiles())[0];
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QFileDialog 'Save As' to non-existent directory

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    mclark (9th September 2010)

  4. #3
    Join Date
    Aug 2006
    Location
    Madison, WI USA
    Posts
    153
    Thanks
    35
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QFileDialog 'Save As' to non-existent directory

    Yes, of course. Can't believe I missed that.

    Thank you for the prompt and problem-solving reply.

Similar Threads

  1. QFileDialog selecting file or directory
    By ^NyAw^ in forum Qt Programming
    Replies: 5
    Last Post: 13th November 2021, 23:03
  2. How to save file with QFileDialog
    By pnikolov in forum Qt Programming
    Replies: 11
    Last Post: 1st June 2012, 10:23
  3. QFileDialog how to save???
    By unix7777 in forum Newbie
    Replies: 12
    Last Post: 12th February 2010, 17:15
  4. How set default file to save in QFileDialog
    By estanisgeyer in forum Qt Programming
    Replies: 1
    Last Post: 29th January 2009, 12:09
  5. Replies: 1
    Last Post: 14th October 2007, 23:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.