[solved] QFileDialog and cancel button
-
Hi,
How do I detect when the cancel button has been pressed by the user? Using the static QFileDialog, the file selected should be null but when instantiating a QFileDialog "manually", the file selected is not null...
@
QFileDialog dlg( NULL, tr("Save file"));
dlg.setAcceptMode( QFileDialog::AcceptSave );
dlg.exec();QString fileName = dlg.selectedFiles().at(0);
// fileName is not null when user pressed cancel!
@Thanks
-
Try
@
QFileDialog dlg(NULL, tr("Save file"));
dlg.setAcceptMode(QFileDialog::AcceptSave);
QString file_name;
if (dlg.exec())
file_name = dlg.selectedFiles().at(0);
else
// User Hit Cancel
@If your not using the model dialog you can use finished() and result() to check the dialog's reply as well in a similar way.
-
for what you need this? if you try to understand, what dialog state was after closing, then use:
@QFileDialog dlg( NULL, tr("Save file"));
QString fileName;
if(dlg == QDialog::Accepted){
fileName = dlg.selectedFiles().at(0);
}@