Results 1 to 5 of 5

Thread: problem with QFileDialog::getSaveFileName

  1. #1
    Join Date
    Aug 2008
    Posts
    134
    Thanks
    10
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default problem with QFileDialog::getSaveFileName

    Dear All,
    I am using QFileDialog::getSaveFileName() with the option in following way (In Windows):
    QFileDialog::getSaveFileName(this, tr("m_Save As"), QDir::currentPath(),
    tr("%1 Files (*.%2)")
    .arg( QString("BMP"))
    .arg(QString("bmp")), 0, QFileDialog:: DontUseNativeDialog);

    I am facing a problem with the return value. Whenever i specify a file name then returned filename will not have extensions. Ex: If i give "Image1" as file name, the above function will return the string Image1 along with the path instead of Image1.bmp.

    If I dont use "QFileDialog:: DontUseNativeDialog" option then function will return properly e.i Image1.bmp. But I dont want to use native dialog.
    Can anyone suggest how can resolve this problem.???

    Thank you

  2. #2
    Join Date
    Aug 2008
    Posts
    134
    Thanks
    10
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: problem with QFileDialog::getSaveFileName

    please, anyone can help on this ???

  3. #3
    Join Date
    Sep 2008
    Posts
    25
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: problem with QFileDialog::getSaveFileName

    Hi navi1084!

    Yes, the native and non-native file dialogs behave differently, at least on windows. Note that the getSaveFileName function has a QString * selectedFilter parameter. In the selectedFilter you can select a default filter for the dialog, and after the function returns, the text will be changed to the selected filter. For example:
    Qt Code:
    1. QString filter="XML files (*.xml)";
    2. QString fileName=QFileDialog::getSaveFileName(this, tr("m_Save As"), QDir::currentPath(),
    3. "Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)"
    4. , &filter, QFileDialog:: DontUseNativeDialog);
    To copy to clipboard, switch view to plain text mode 
    In this case the xml filter will be selected by default, otherwise the default filter would be the first one in the list. Here comes the important part for us, after the function returns and in case you have selected the second filter the filter strings contents will be "Text files (*.txt)". By knowing the selected filter, you can decide which extension to append to the file name.

  4. #4
    Join Date
    May 2008
    Posts
    24
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: problem with QFileDialog::getSaveFileName

    Exactly.

    First take the user selected filter using selectedFilter parameter. Then, make your effort to give correct extension based on the selected filter.

    However, the selectedFilter parameter doesn't work well under Linux until Qt 4.5.1. Such a problem does not occur under Windows nor under Mac OS.

  5. #5
    Join Date
    Aug 2008
    Posts
    134
    Thanks
    10
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: problem with QFileDialog::getSaveFileName

    Thanks for the reply and i agree what you are telling.
    But when we use native dialog, the returned file name will be along with the extensiton. for example if user type name as Image1 and filter is *.BMP, then returned string will be image1.bmp. but is i am not using the native dialog then returned string is only Image1. Hence to append proper extension i need to do some work around (especially if user already types the extension).
    Ultimately Qt's FileDialog doesn't act same as native dialog.

Similar Threads

  1. Replies: 19
    Last Post: 4th April 2009, 00:17
  2. Very strange socket programming problem
    By montylee in forum Qt Programming
    Replies: 5
    Last Post: 11th November 2008, 13:05
  3. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 10:12
  4. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 09:47
  5. Replies: 16
    Last Post: 7th March 2006, 16:57

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.