Results 1 to 3 of 3

Thread: Differences in QFileDialog::getSaveFileName between Windows and Linux

  1. #1
    Join Date
    Mar 2009
    Posts
    19
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Differences in QFileDialog::getSaveFileName between Windows and Linux

    I'm seeing an aggravating difference in the behavior of QFileDialog::getSaveFileName on Windows vs. Linux. The difference is and whether or not the correct file name extension is automatically appended to the filename that the user enters. For example:

    Qt Code:
    1. QString fileName = QFileDialog::getSaveFileName(parent,
    2. "Select save location",
    3. "Text Files (*.txt)");
    To copy to clipboard, switch view to plain text mode 

    On Windows, if the user enters "temp" as the filename and clicks okay, the variable "fileName" will contain the string "temp.txt". On Linux, it will only contain the string "temp".

    I would much prefer the behavior that I see on Windows, so that I don't have to implement this behavior myself every time I use this method. Does anyone have any ideas about how to get the correct behavior on Linux, or is this just a bug have to deal with for the time being?

    I'm using Qt 4.5.1.

  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: Differences in QFileDialog::getSaveFileName between Windows and Linux

    As default in MS Windows QFileDialog::getSaveFileName uses native Dialogs
    A camel can go 14 days without drink,
    I can't!!!

  3. #3
    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: Differences in QFileDialog::getSaveFileName between Windows and Linux

    Quote Originally Posted by negritot View Post
    I would much prefer the behavior that I see on Windows, so that I don't have to implement this behavior myself every time I use this method.
    It's enough if you implement it once and reuse the code afterwards...

    Qt Code:
    1. QString getSaveFileNameWithExtension(QWidget * parent = 0, const QString & caption = QString(),
    2. const QString & dir = QString(), const QString & filter = QString(),
    3. QString * selectedFilter = 0, Options options = 0){
    4. QString res = QFileDialog::getSaveFileName(parent, caption, dir, filter, selectedFilter, options);
    5. #ifndef Q_OS_WIN
    6. if(selectedFilter){
    7. QRegExp filterRx(".*\\(\\*\\.(.*)\\)");
    8. if(filterRx.exactMatch(*selectedFilter))
    9. res.append("."+filterRx.cap(1));
    10. }
    11. #endif
    12. return res;
    13. }
    To copy to clipboard, switch view to plain text mode 
    Note this of course won't work if you select a filter such as "Images (*.png *.xpm *.jpg)" but I understand it wouldn't work on Windows either.
    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. Deployment Procedure On Windows On Linux and Windows
    By Harshith J.V. in forum Installation and Deployment
    Replies: 4
    Last Post: 9th July 2009, 11:27
  2. Replies: 2
    Last Post: 4th June 2009, 16:09
  3. Replies: 5
    Last Post: 15th January 2009, 09:03
  4. QPalette works differently on windows and linux
    By babu198649 in forum Newbie
    Replies: 3
    Last Post: 6th March 2008, 07:27
  5. Replies: 4
    Last Post: 12th January 2006, 04:16

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.