开发者

QT Open default file explorer on *nix

开发者 https://www.devze.com 2023-01-12 21:50 出处:网络
I have the following: QProcess *process = new QProcess(this); QString path = QDir::toNativeSeparators(QApplication::applicationPath);

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消