Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open External Browser from QWebView

Tags:

qt

qwebview

I have a "start page" on my application that is just a QWebView widget that downloads a page from my server.

When the user clicks on a link I'd like it to open in their default browser, not in the widget.

Is there a way to do this with QWebView? Or should I take a different approach?

like image 456
Mark Beckwith Avatar asked Apr 12 '09 16:04

Mark Beckwith


1 Answers

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

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

like image 190
PiedPiper Avatar answered Oct 15 '22 11:10

PiedPiper