Results 1 to 3 of 3

Thread: file name returned by QFileDialog::getSaveFileName()

  1. #1
    Join Date
    Feb 2008
    Posts
    11
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default file name returned by QFileDialog::getSaveFileName()

    Hello all, using Qt 4.3.3 and Open Suse 10.3

    I'm trying to use the static function QFileDialog::getSaveFileName and I notice that the file name returned doesn't have the file extension that is specified in the selected filter appended to it. This renders the overwrite check useless as it's looking for the filename without an extenstion when the filename should have one.

    Some code to illustrate:

    Qt Code:
    1. QString fileName;
    2. QString filter = tr("My Files (*.ggg)");
    3.  
    4. fileName = QFileDialog::getSaveFileName(this, tr("Dlg title"), tr("/home/temp/"), filter);
    5. qDebug() << fileName;
    To copy to clipboard, switch view to plain text mode 

    now when this code is executed I would expect fileName to have a .ggg extenstion but it's only the path + the text the user entered in the lineEdit for the filename. So if the user didn't type in the extension (in this case .ggg) it's not included in the filename returned. The overwrite check is looking for the filename with no extenstion, so it doesn't complain. I've tried setting the selectedFilter in the function call and this makes no change in my result.

    Am I doing something incorrectly or is this just how it works?
    Obviously I can check the filename and add the extension, but I'd like to use the overwrite check so I don't have to close the dialog and reopen it just so the user can pick another name.

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: file name returned by QFileDialog::getSaveFileName()

    QFileDialog::getSaveFileName() doesn't add extension to fileName this because you can select a "multiple extension filter".
    For example

    Qt Code:
    1. fileName = QFileDialog::getSaveFileName(this, tr("Open File"), "", tr("Image Files (*.png *.bmp *.jpg)"));
    To copy to clipboard, switch view to plain text mode 

    Then you ave to specify the extension
    A camel can go 14 days without drink,
    I can't!!!

  3. #3
    Join Date
    Feb 2008
    Posts
    11
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: file name returned by QFileDialog::getSaveFileName()

    Quote Originally Posted by mcosta View Post
    QFileDialog::getSaveFileName() doesn't add extension to fileName this because you can select a "multiple extension filter".

    Then you have to specify the extension
    Makes sense. Thanks.

Similar Threads

  1. Set up the Qt4.3.2 with Visual Studio 2005
    By lamoda in forum Installation and Deployment
    Replies: 6
    Last Post: 30th January 2008, 06:51
  2. EXE File problem
    By triperzz in forum Installation and Deployment
    Replies: 8
    Last Post: 18th January 2008, 19:00
  3. file renaming on windows
    By jdd81 in forum Qt Programming
    Replies: 9
    Last Post: 2nd October 2007, 19:41
  4. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21
  5. Sending Binary File with QFTP
    By nbkhwjm in forum Newbie
    Replies: 2
    Last Post: 7th March 2007, 18: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.