[Qt-interest] Launching new browser from within QtWebKit

Nguyen Huu Phuoc nhphuoc at vn.isb.co.jp
Thu Jan 20 02:16:09 CET 2011


Hi Darryl


I know that QWebView has a signal is void QWebView::linkClicked ( const QUrl
<http://doc.trolltech.com/4.6/qurl.html>  & url )


You should write your slot to process this signal.


If url has target=’_blank” you should call default browser to load url


Otherwise you should use QWebView to load url.


Hope help you a bit.


Nguyen Huu Phuoc

阮 有 福-グエン.ヒュー.フォック

ISB VIETNAM Co., Ltd (IVC)

nhphuoc at vn.isb.co.jp

  _____

From: qt-interest-bounces+nhphuoc=vn.isb.co.jp at qt.nokia.com
[mailto:qt-interest-bounces+nhphuoc=vn.isb.co.jp at qt.nokia.com] On Behalf Of
Darryl Hunter
Sent: Thursday, January 20, 2011 8:01 AM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] Launching new browser from within QtWebKit



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





____________________________________________________________________________
This email is intended for the sole use of the intended recipient/s. Any review or copying or distribution or forwarding of any or all of the contents in this message is strictly prohibited. If you were not the intended recipient, please contact the sender by email and delete all copies; your cooperation in this regard is appreciated.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110120/1ca6b9f1/attachment.html 


More information about the Qt-interest-old mailing list