[Qt-interest] Launching new browser from within QtWebKit
Darryl Hunter
darryl.hunter at codersoft.com.au
Sat Mar 5 00:07:52 CET 2011
Hi Alan,
The createWindow method only gets called if target="_blank" has been set on
the target. I assume that gets handled by the acceptNavigationRequest
method.
It works fine on Mac as well as Windows.
Darryl
-----Original Message-----
From: Alan Ezust [mailto:alan.ezust at gmail.com]
Sent: Saturday, 5 March 2011 6:01 AM
To: Darryl Hunter
Cc: qt-interest at trolltech.com
Subject: Re: [Qt-interest] Launching new browser from within QtWebKit
I was googling and looking for an answer to this very same question.
But looking at your code, it is not obvious where you are able to determine
whether the <a href> element had a target="_blank" attribute in it.
But I am in the same boat. I want to know if the clicked link came from a
<a> tag with a target= and I want to create a new web view in such a case.
Do you get a different NavigationType in your
acceptNavigationRequest() function, or what?
On Sat, Jan 22, 2011 at 11:12 PM, Darryl Hunter
<darryl.hunter at codersoft.com.au> wrote:
> Hi everybody,
>
>
>
> My final post on this - I managed to get it solved so thought I'd post
> the solution (largely influenced by the Browser demo).
>
>
>
> I had to subclass QWebPage as follows:
>
>
>
> class MyWebPage : public QWebpage
>
> {
>
> public:
>
> MyWebPage (QObject *parent) : QWebPage(parent) {};
>
> MyWebPage::~ MyWebPage () {};
>
>
>
> protected:
>
> bool acceptNavigationRequest(QWebFrame *frame, const
> QNetworkRequest &request, NavigationType type)
>
> {
>
> theurl=request.url();
>
>
>
> return QWebPage::acceptNavigationRequest (frame, request,
> type);
>
> }
>
>
>
> QWebPage * createWindow(QWebPage::WebWindowType type)
>
> {
>
> QDesktopServices::openUrl (theurl);
>
>
>
> return 0;
>
> }
>
>
>
> private:
>
> QUrl theurl;
>
> };
>
>
>
> Then I had to tell the web view about this new class:
>
>
>
> ui.webview->setPage (new MyWebPage (ui.webview));
>
>
>
> I'm yet to see the results on my mac target, but it all works well on
> my Windows 7 / Qt 4.7.1 / VS2008 development machine.
>
>
>
> Thanks to those who gave me suggestions.
>
>
>
> Darryl
>
>
>
>
>
>
>
> From: Darryl Hunter [mailto:darryl.hunter at codersoft.com.au]
> Sent: Thursday, 20 January 2011 12:01 PM
> 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.
>
>
More information about the Qt-interest-old
mailing list