c++ - Append missing extension to result of QFileDialog -
By using
One suggestion was to add an extension manually after the fact that the problem with this approach is that the user can not be warned that they are overwriting the file (for example, test.txt exists, the user enters test and is not indicated that they are actually overwriting test.txt ) I have read all the documents on Unfortunately, it seems that when you are using the "native" file dialog, this functionality Not available . However, it works as if you expect that you use the QT file dialog. Here's how you can use the QT file dialog: As an alternative, you can apply your own overwrite verification: QFileDialog , I prompt the user for a file name and add an extension I am missing.
QFileDialog and I E has not been successful. I tried
setDefaultSuffix , but the result of
fileDialog.getSaveFileName () was not expanded. Can someone provide an example of how to do it successfully?
QFileDialog saveDialog; SaveDialog.setAcceptMode (QFileDialog :: AcceptSave); SaveDialog.setDefaultSuffix ("txt"); SaveDialog.exec (); QString file = saveDialog.selectedFiles (). first ();
QString file; Do {file = QFileDialog :: getSaveFileName (); If (! File.endsWith (".txt")) {file.append (".txt"); If (QFile :: exist (file)) {if (QMessageBox :: Yes! = QMessageBox :: question (NULL, QString (), "Confirmation Overwrite?", QMessageBox :: Yes | QMessageBox :: No) {file. clear(); }}}} Whereas (file.isEmpty ());
Comments
Post a Comment