Qt Tutorials For Beginners – QFileDialog::getOpenFileName 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::getOpenFileName

Basic syntax of QFileDialog::getOpenFileName

This is a convenience static function that returns an existing file selected by the user. If the user presses Cancel, it returns a null string.

 

Now Lets create a Program and see how we can use QFileDialog::getOpenFileName 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 getOpenFileName Demo
QFileDialog getOpenFileName Demo

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

OUTPUT

 


Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com


  • Mouctar

    to make a C # application on windows allows us to integrate a linux terminal, an analyzer and detect the networks equipment such as routers are …. this is possible? in fact to make in C # an application on windows allows us to integrate a linux terminal, an analyzer and detect the networks equipment such as routers are …. this is possible?

  • Mouctar

    hi i want to make a C # application on windows allows us to integrate a linux terminal, an analyzer and detect the networks equipment such as routers are …. this is possible? in fact to make in C # an application on windows allows us to integrate a linux terminal, an analyzer and detect the networks equipment such as routers are …. this is possible?