[Qt-interest] Force file extension with QFileDialog::getSaveFileName?

Eric Clark eclark at ara.com
Tue Jun 21 22:47:44 CEST 2011


I am not real sure why it is not working, but maybe I am not telling you the right thing to do. I have never tested the setDefaultSuffix function out, so I was just giving you what I thought it was supposed to do. We do not use this function, instead we just add the extension if it is not there like I suggested you would have to do with the static function. I am guessing you will have to do the same thing. Here is an example of what to do:

QString fileName = QFileDialog::getSaveFileName(...);
QFileInfo file(filename);
if(file.suffix().isEmpty()) fileName += ".txt";

This example does not look at the selected extension. So, you may want to pass in a parameter for the selected extension and use the one the user had selected when they selected the file instead of just choosing one.

Sorry the other stuff did not work :(

Eric

> -----Original Message-----
> From: David Doria [mailto:daviddoria at gmail.com]
> Sent: Tuesday, June 21, 2011 11:53 AM
> To: Eric Clark
> Cc: Qt Interest (qt-interest at trolltech.com)
> Subject: Re: [Qt-interest] Force file extension with
> QFileDialog::getSaveFileName?
> 
> Nope, it's still not appending the suffix.
> 
> David



More information about the Qt-interest-old mailing list