Qt Tutorials For Beginners – QFileDialog::getOpenFileNames Example

In this lesson we will learn how to use QFileDialog in qt.
The QFileDialog class provides a dialog that allow users to select files or directories.
First lets see how to use static function QFileDialog::getOpenFileNames

Basic syntax of QFileDialog::getOpenFileNames

This is a convenience static function that will return one or more existing files selected by the user.

Now Lets create a Program and see how we can use QFileDialog::getOpenFileNames in practice

File->New File or Project…
Applications->Qt Gui Application->Choose…
We keep the class as MainWindow as given by default.

Now write the code below in main.cpp

Now build and run the program.

QFileDialog getOpenFileNames Demo
QFileDialog getOpenFileNames Demo

After selecting the file using open file dialog this code will print the paths of the selected files in console.


Partner Sites