C++ 如何在 Qt 的默认用户浏览器中打开链接?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10250332/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 13:48:01  来源:igfitidea点击:

How to open a link in a default user browser in Qt?

c++qt

提问by myWallJSON

I wonder how to open a link in a default user browser using Qt (that would open it across all platforms (Win Mac Lin))?

我想知道如何使用 Qt 在默认用户浏览器中打开链接(可以在所有平台上打开它(Win Mac Lin))?

回答by jdi

In the doc: QDesktopServices

在文档中:QDesktopServices

http://doc.qt.io/qt-4.8/qdesktopservices.html#openUrl

http://doc.qt.io/qt-4.8/qdesktopservices.html#openUrl

bool QDesktopServices::openUrl ( const QUrl & url ) [static]

Opens the given url in the appropriate Web browser for the user's desktop environment, and returns true if successful; otherwise returns false.

在用户桌面环境的适当 Web 浏览器中打开给定的 url,如果成功则返回 true;否则返回false。

回答by Tan Viet

You can try this code

你可以试试这个代码

QString link = "http://www.google.com";
QDesktopServices::openUrl(QUrl(link));

Read QDesktopServicesand QUrlto get further information.

阅读QDesktopServicesQUrl以获取更多信息。

回答by Nathan Boyd

you are looking for openUrl() in the desktop services class

您正在桌面服务类中寻找 openUrl()

http://qt-project.org/doc/qt-4.8/QDesktopServices.html

http://qt-project.org/doc/qt-4.8/QDesktopServices.html