简体   繁体   中英

QFileDialog - Saving a file with specified file name

How can I let the user save a file using QFileDialog without allowing the user to change the file name?

I have been using this code:

QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),"commands.txt", tr("TXT files (*.txt)"));

However, it allows the user to change the file name. I want it so that the user can't change the file name and can only save the file under "commands.txt".

If you want to choose the folder to save commands.txt use QFileDialog::getExistingDirectory and save the file into the specified folder. Don't forget to check returned string isEmpty() , this means that user clicked "cancel".

If you want to let user decide to save commands.txt or not use QMessageBox with Yes and No buttons.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM