kehao
kehao

Reputation: 221

How to launch a file browser in a Qt application?

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?

Upvotes: 21

Views: 46721

Answers (2)

ChrisV
ChrisV

Reputation: 3423

Use QFileDialog::getOpenFileName.

Upvotes: 22

Mevin Babu
Mevin Babu

Reputation: 2475

What you need to do is write this code in your mouse_click function !

QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Open File"),"/path/to/file/",tr("Mp3 Files (*.mp3)"));
ui->listWidget->addItems(fileNames);

*.mp3 will display only mp3 files remove the tr("Mp3 Files (*.mp3)") if you dont want to filter any files

Upvotes: 19

Related Questions