0

I'm new to qt, and I have a button, if I click on it I want to get a dialog box to choose a path where I want to save a file. My question is, how could I create this kind of dialog box, which returns with a string of the path? I use linux, if it matters with qt:)

ps.: I use only gedit, so I'd like to solve it that way. :)

4

2 回答 2

2

Use QFileDialog which has several useful static member functions including

QString myDir = QFileDialog::getExistingDirectory();

which returns a directory that you select. I think that is what you want, see the docmentation here

http://qt-project.org/doc/qt-5.0/qtwidgets/qfiledialog.html

于 2013-07-27T12:20:56.833 回答
1

In addition to the answer by @Muckle_ewe, there is a the static function QFileDialog::getSaveFileName, which will present the standard open / save file dialog and allow the user to both select the path and input a name for the file.

It's definition is this: -

QString QFileDialog::getSaveFileName(QWidget * parent = 0, const QString & caption = QString(), const QString & dir = QString(), const QString & filter = QString(), QString * selectedFilter = 0, Options options = 0)

An example of its usage is: -

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

As the docs state,

This is a convenience static function that will return a file name selected by the user. The file does not have to exist.

于 2013-07-29T16:09:28.873 回答