Results 1 to 4 of 4

Thread: QFileDialog and file extension

  1. #1
    Join Date
    Oct 2007
    Location
    Grenoble, France
    Posts
    80
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QFileDialog and file extension

    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.
    You have to run a level 3 diagnostic.

    Ashes to ashes, Qt to Qt ( wysota )

  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 and file extension

    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).

  3. #3
    Join Date
    Mar 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QFileDialog and file extension

    Hi,

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

  4. #4
    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 and file extension

    Why would Qt insert the extension automatically (especially when you are using a native dialog)?

    Qt Code:
    1. QString path = QFileDialog::getSaveFileName(...);
    2. if(path.isEmpty()) return;
    3. if(!path.endsWith(".ext"))
    4. path.append(".ext");
    To copy to clipboard, switch view to plain text mode 
    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.


Similar Threads

  1. QFileDialog and file sequences
    By peterhillman in forum Qt Programming
    Replies: 5
    Last Post: 24th November 2007, 11:16
  2. How to read text only as it is from file
    By thomasjoy in forum Qt Programming
    Replies: 3
    Last Post: 9th August 2007, 09:47
  3. Replies: 4
    Last Post: 13th June 2007, 16:37
  4. QFileDialog in Qt designer
    By tpf80 in forum Qt Tools
    Replies: 1
    Last Post: 17th May 2007, 01:41
  5. dialog box
    By Bahar in forum Qt Programming
    Replies: 3
    Last Post: 31st January 2006, 15:52

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.