qt - 如何获取系统的默认浏览器?

Qt有获取系统默认浏览器的接口(interface)吗?

我想在浏览器中显式打开一个 file:// url 而不是系统的默认应用程序,所以 QDesktopServices::openUrl不是因为

If the URL is a reference to a local file (i.e., the URL scheme is "file") then it will be opened with a suitable application instead of a Web browser.

最佳答案

对于您的特定应用程序,您应该使用 Qt 附带的 Web 引擎:

QWebEngineView *view = new QWebEngineView{parent};
view->load(QUrl{"file://...."});
view->setWindowFlags(Qt::Window);
view->setAttribute(Qt::WA_DeleteOnClose);
view->show();

如果html足够简单,使用文本浏览器:

QTextBrowser *view = new QTextBrowser{parent};
view->setSource(Qurl{"file://...."});
view->setWindowFlags(Qt::Window);
view->setAttribute(Qt::WA_DeleteOnClose);
view->show();

https://stackoverflow.com/questions/38954534/

相关文章:

java - org.springframework.security.authentication

java - 未找到包含 : org. eclipse.update.feature、org.ecl

macos - 如何让 macOS 虚拟机以安全模式启动?

java - artemis rest 集成 - 无法使用队列中的消息

python - 重构模块名称后unpickle实例

android - 如何在 Retrofit2 converter-simplexml 中调试 "j

linux - 有没有办法从 git lfs 指针下载实际文件?

php - 正则表达式 yii2 电话号码验证器

apache-spark - 从 pyspark 矩阵分解模型中检索潜在因子

javascript - d3 读取输入值