QFileDialog dialog; dialog.setAcceptMode(QFileDialog::AcceptOpen); dialog.exec();
QFileDialog dialog; dialog.setAcceptMode(QFileDialog::AcceptFolder); dialog.exec();This code creates a QFileDialog instance and sets the accept mode to select a directory. When the user selects a directory and clicks the Ok button, the exec() function is called to display the dialog box. Package library: Qt5Widgets.