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
How to open a link in a default user browser in 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.
阅读QDesktopServices和QUrl以获取更多信息。
回答by Nathan Boyd
you are looking for openUrl() in the desktop services class
您正在桌面服务类中寻找 openUrl()