Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to launch a file browser in a Qt application?

Tags:

I want to have a button that, when clicked, launches a file browser (like Ctrl + O in Word) and returns the path of the file that user opens.

I know how to make the button, but what should I do in the slot that responds to mouseClicked signal?

like image 703
kehao Avatar asked Apr 09 '11 04:04

kehao


People also ask

How do I load a file in Qt?

abk file to load it into the address book. void AddressBook::loadFromFile() { QString fileName = QFileDialog::getOpenFileName(this, tr("Open Address Book"), "", tr("Address Book (*. abk);;All Files (*)")); On Windows, for example, this function pops up a native file dialog, as shown in the following screenshot.

How do I open and read a file in Qt?

open(QIODevice::WriteOnly) and then write data to it. Similarly, to get data out of a file, you will need to call file. open(QIODevice::ReadOnly) and then read the data. You can do whatever you want with the data after that.


1 Answers

Use QFileDialog::getOpenFileName.

like image 110
ChrisV Avatar answered Sep 21 '22 15:09

ChrisV