Open external browser from QWebView

I have a "start page" in my application, it's just a QWebView widget that downloads the page from my server.

When the user clicks the link that I would like to open in the default browser, and not in widgets.

Is there a way to do this using QWebView ? Or should I use a different approach?

+4
source share
2 answers

Just call QWebPage :: setLinkDelegationPolicy (QWebPage :: DelegateAllLinks), then connect the signal QWebView :: linkClicked (const QUrl and url) to the slot, and in the slot, execute the browser. Finding out what the default browser is is a bit more complicated and depends on which user's desktop is running. The BROWSER environment variable often contains a default value.

Or use QDesktopServices :: openUrl [as suggested by gnud in the comment]

+13
source

Assuming the links are external, you can simply call QWebView :: setOpenExternalLinks (true) in the QWebView widget. The default property is false; setting it to true, external external links will open in your web browser by default.

0
source

All Articles