天天看點

Qt檔案儲存對話框預設儲存檔案

在調用Qt檔案對話框用來儲存檔案時,有時候希望提供預設的檔案名,具體該如何做呢?

The file dialog’s working directory will be set to dir. If dir includes a file name, the file will be selected. Only files that match the filter are shown. The filter selected is set to selectedFilter. The parameters dir, selectedFilter, and filter may be empty strings. Multiple filters are separated with ‘;;’。

如果設定了dir,則檔案對話框會将此dir當工作目錄,如果dir包括檔案名,則會選擇該檔案。隻有當檔案跟過濾相比對時才顯示,標明的過濾器設定為selectedFilter。參數dir、selectedFilter和filter可以是空字元串。多個過濾器用“;;”分隔。

也就是說當dir包含檔案名時,此檔案名就是預設的儲存檔案名。例如:

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

繼續閱讀