Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

qt

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

like image 999
myWallJSON Avatar asked Apr 20 '12 16:04

myWallJSON


People also ask

Can QT be used for Web application?

To create Qt-based web applications, Qt provides interfaces that support a wide range of standard web techologies such as HTML, CSS, and JavaScript. These interfaces enable applications to embed content from the World Wide Web.

Is Qt Creator cross-platform?

Qt Creator is a cross-platform IDE for C++ and QML.

What API does Qt use?

Graphics in Qt 5 is primarily done either through the imperative QPainter API, or through Qt's declarative UI language, Qt Quick, and its scene graph back-end. Qt 5's graphics capabilities also includes support for printing, as well as the loading and saving of various image formats.


2 Answers

In the doc: QDesktopServices

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.

like image 73
jdi Avatar answered Oct 09 '22 10:10

jdi


You can try this code

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

Read QDesktopServices and QUrl to get further information.

like image 36
Tan Viet Avatar answered Oct 09 '22 10:10

Tan Viet