Gad D Lord
Gad D Lord

Reputation: 6772

QT Open default file explorer on *nix

I have the following:

QProcess *process = new QProcess(this);
QString path = QDir::toNativeSeparators(QApplication::applicationPath);
#if defined(Q_OS_WIN)

process->start("explorer.exe",  QStringList() << path);

#elif defined(Q_OS_MAC)

process->start("open", QStringList() << path);

#endif

How I can achieve the same behavior for let say Ubuntu?

Upvotes: 17

Views: 7940

Answers (1)

user362638
user362638

Reputation:

Use QDesktopServices and its openUrl function:

QString path = QDir::toNativeSeparators(QApplication::applicationDirPath());
QDesktopServices::openUrl(QUrl::fromLocalFile(path));

It should work with all OS'es. I have tested it only in Windows.

Upvotes: 40

Related Questions