[Qt-interest] Force file extension with QFileDialog::getSaveFileName?
David Doria
daviddoria at gmail.com
Tue Jun 21 22:55:39 CEST 2011
On Tue, Jun 21, 2011 at 4:47 PM, Eric Clark <eclark at ara.com> wrote:
> 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
That method works fine, thanks. However, since we both expected the
same thing from the defaultSuffix, we should probably alert the devs
so they can clarify the documentation, don't you think?
David
More information about the Qt-interest-old
mailing list