youssef6342
youssef6342

Reputation: 39

How to open a file explorer from Qt?

I want to open a file explorer which will be independent from the application, and will act exactly like if the user opens a file explorer from Desktop. I do not need QFileDialog since I do not need to know what file will the user choose.

Upvotes: 1

Views: 2461

Answers (2)

Pablo Yaggi
Pablo Yaggi

Reputation: 1221

You should use the desktop services, it will open the available application to handle the url you pass to it. The following opens a file browser in the root directory.

#include <QDesktopServices>
#include <QUrl>

QDesktopServices::openUrl(QUrl("file:///"));

Upvotes: 4

Ihor Drachuk
Ihor Drachuk

Reputation: 1293

Try QProcess

#include <QProcess>

int main(int argc, char *argv[])
{
    QProcess::startDetached("C:\\Windows\\explorer.exe", {});
    return 0;
}

Upvotes: 2

Related Questions