QT打开* nix上的默认文件浏览器 [英] QT Open default file explorer on *nix

查看:258
本文介绍了QT打开* nix上的默认文件浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下内容:

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

我可以如何实现同样的行为让Ubuntu ?

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

推荐答案

使用 QDesktopServices 及其openUrl函数:

Use QDesktopServices and its openUrl function:

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

它应该适用于所有的操作系​​统。我只在Windows中测试过。

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

这篇关于QT打开* nix上的默认文件浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆