简体   繁体   English

需要使用QFileDialog保存新文件

[英]Need to save a new file with QFileDialog

I am attempting to give the user an option of saving a file using QFileDialog However if the file does not exist the File Dialog states that the file does not exist. 我试图给用户一个使用QFileDialog保存文件的选项但是如果该文件不存在,则文件对话框指出该文件不存在。 I want the QfileDialog to simply tell me the name of the file the user typed so that I can create it. 我希望QfileDialog只是告诉我用户键入的文件的名称,以便我可以创建它。 I am doing the following 我正在做以下事情

QFileDialog::getOpenFileNames(this, tr("Save File"))

and then create a file using the returned string. 然后使用返回的字符串创建一个文件。

Use QFileDialog::getSaveFileName instead getOpenFileNames : 使用QFileDialog :: getSaveFileName代替getOpenFileNames

 QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),
                            "/home/jana/untitled.png",
                            tr("Images (*.png *.xpm *.jpg)"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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