#includeQString fileName = QFileDialog::getOpenFileName(this, "Open File", "/home/", "Text Files (*.txt);;All Files (*.*)"); if (!fileName.isEmpty()) { // do something with the selected file }
#includeIn this example, we create a QFileDialog object and call its `getSaveFileName()` method which opens a dialog box for the user to select a file name and location to save a file. The method takes the same arguments as the `getOpenFileName()` method. Package library: Qt (QtCore)QString fileName = QFileDialog::getSaveFileName(this, "Save File", "/home/", "Text Files (*.txt);;All Files (*.*)"); if (!fileName.isEmpty()) { // save contents to the selected file }