[Qt-interest] Force file extension with QFileDialog::getSaveFileName?
Eric Clark
eclark at ara.com
Tue Jun 21 17:52:05 CEST 2011
If you create your own dialog, you can use QFileDialog::setDefaultSuffix. But if you use the static functions, you will need to implement the logic on your own. It should be fairly easy to do though:
QString fileName = QFileDialog::getSaveFileName(...);
QFileInfo file(filename);
if(file.suffix().isEmpty()) fileName += ".txt";
The above code is an example of the logic to add the default extension ".txt".
Eric
> -----Original Message-----
> From: qt-interest-bounces+eclark=ara.com at qt.nokia.com [mailto:qt-
> interest-bounces+eclark=ara.com at qt.nokia.com] On Behalf Of David Doria
> Sent: Tuesday, June 21, 2011 10:41 AM
> To: qt-interest at qt.nokia.com
> Subject: [Qt-interest] Force file extension with
> QFileDialog::getSaveFileName?
>
> When I use QFileDialog::getSaveFileName, it allows the user to type any file
> name. What I would like to do is ensure the result of this dialog ends with
> one of the valid extensions specified by the filter (*.png *.bmp - etc). Is
> there an option for this?
>
> Thanks,
>
> David
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list