Unfortunately, it looks like this functionality is not available when you're using the "native" file dialog. However, it works just as you expected if you use the Qt file dialog.
Here's how you can use the Qt file dialog:
QFileDialog saveDialog;
saveDialog.setAcceptMode(QFileDialog::AcceptSave);
saveDialog.setDefaultSuffix("txt");
saveDialog.exec();
QString file = saveDialog.selectedFiles().first();
As an alternative, you can implement your own overwrite validation:
QString file;
do
{
file = QFileDialog::getSaveFileName();
if(!file.endsWith(".txt"))
{
file.append(".txt");
if(QFile::exists(file))
{
if(QMessageBox::Yes != QMessageBox::question(NULL, QString(), "Confirm overwrite?", QMessageBox::Yes | QMessageBox::No))
{
file.clear();
}
}
}
} while (file.isEmpty());