12

We're building a Qt Quick app, that must be able to save a file under a given name.

In the FileDialog component you can only set a directory. This is not very user-friendly, since you don't want to type in a filename by hand every time you download a file.

So far we tried different things

  1. FileDialog from QtQuick.Dialogs: filename cannot be set

  2. Native dialog via QPlatformFileDialogHelper (naughty private c++ hack): filename cannot be set on Linux (Gnome)

  3. Native dialog via static QFileDialog::getSaveFileName(): in Quick application there is no QWidget available for 'parent'

  4. QT dialog via QFileDialog instance: Modality doeas not work, since 'parent' is not set. In Quick application there is no QWidget available for setParent() call

(Using C++ with QT 5.1 and QtQuick 2.1 incl. all desktop components)

4

3 回答 3

6

这篇博文涵盖了整个问题并提供了一个可能的解决方案: QML 中的 Advanced FileDialog(以给定名称保存文件)(RIP Kullo 博客)

实现该解决方案的存储库在这里:https ://github.com/kullo/qml-file-dialog-demo

于 2013-12-27T13:58:24.443 回答
4

我希望这仍然会有所帮助。我找到了一个至少对我有用的折衷方案。我使用 Qt.labs.platform 1.1 FileDialog QML 类型:https ://doc.qt.io/qt-5/qml-qt-labs-platform-filedialog.html

FileDialog {
            id: saveDialog
            property MyClass myObj
            title: "Save Dialog"
            folder: myObjHasAPath? myObj.path: "file:///" //Here you can set your default folder
            currentFile: "file:///"+myObj.name //The name of the item that you want to save
            fileMode: Platform.FileDialog.SaveFile
        }
于 2019-03-20T15:27:25.197 回答
2

尝试将 FileDialog 的 selectExisting 属性设置为 false。

于 2017-04-06T13:31:42.517 回答