[Qt-interest] Launching new browser from within QtWebKit
Darryl Hunter
darryl.hunter at codersoft.com.au
Thu Jan 20 02:00:56 CET 2011
Hi all,
I posted this on the weekend and had one response, which isn't quite
flexible enough for my requirements. Does anybody else have any
suggestions?
My issue is that I need to *optionally* spawn a new browser from within a
QWebView. When I set target="_blank", it won't launch the page.
I was given the suggestion of connecting to the linkClicked signal and using
QDesktopServices::openUrl, which works when following links, but does it for
*all* links. I only want to do this if target="_blank".
Any suggestions?
Thanks.
Darryl
From: Darryl Hunter [mailto:darryl.hunter at codersoft.com.au]
Sent: Sunday, 16 January 2011 6:31 PM
To: 'sarvesh saran'; 'qt-interest at trolltech.com'
Subject: RE: [Qt-interest] Launching new browser from within QtWebKit
Thanks Sarvesh.
I implemented your suggestion and that worked for opening the default
browser.
However, one part I omitted from the original post, was that not *all* of
the links should open a browser - sometimes I want it to stay within the
existing window. So I need it to look at that target="_blank" part
somewhere in between to determine whether to handle it in the WebView or
start the default browser. This isn't in the QUrl object though (from what
I understand - happy to be proven wrong on this point!).
Darryl
From: sarvesh saran [mailto:aquarian.thunder at gmail.com]
Sent: Sunday, 16 January 2011 5:02 PM
To: qt-interest at trolltech.com
Cc: Darryl Hunter
Subject: Re: [Qt-interest] Launching new browser from within QtWebKit
Hi,
I remember facing this same issue a long time ago. You can try the following
:
webView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
connect(webView, SIGNAL(linkClicked(const QUrl&)), this, SLOT
(onUrlClicked(const QUrl&)));
in the slot, use QDesktopServices::openUrl to open the url in your default
browser:
http://doc.trolltech.com/4.5/qdesktopservices.html#openUrl
( if using Linux, you can try and check if $BROWSER env variable is
set...and then use QProcess to open that browser, passing the Url as a
command line arg)
thanks,
Sarvesh Saran
On Sun, Jan 16, 2011 at 5:58 AM, Darryl Hunter
<darryl.hunter at codersoft.com.au> wrote:
Hi all,
I'm using Qt 4.7.1, on Windows 7. My application has a QWebView in it,
which has loaded a page from my server. I want to have a link that, when
clicked, opens the users default browser to show the page, rather than
opening it within the QWebView.
I set target="_blank" on the page, and it works fine when I test it within
Internet Explorer (a new copy of IE is launched), but when I follow the link
within the QWebView, nothing happens. If I don't have the target="_blank"
then it follows the link as you would expect (within the QWebView).
Is there a setting I need to enable to make this happen? I couldn't see
anything in QWebSettings that appeared relevant.
Any help / suggestions would be greatly appreciated.
Regards,
Darryl
_______________________________________________
Qt-interest mailing list
Qt-interest at qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110120/3158f9c3/attachment.html
More information about the Qt-interest-old
mailing list