FileDialog in QTQuick (QML): Save file under given name

Simon Warta picture Simon Warta · Nov 30, 2013 · Viewed 12.1k times · Source

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)

Answer

Simon Warta picture Simon Warta · Dec 27, 2013

This blog post covers the whole problem and provides a possible solution: Advanced FileDialog in QML (Save file under given name)