Results 1 to 2 of 2

Thread: QWebView linkClicked

  1. #1
    Join Date
    May 2011
    Qt products

    Default Re: QWebView linkClicked


    When set to QWebPage:elegateAllLinks a clickLink signal is taking over the click. But how to actually continue loading the link. So let say when I click on link it opens the url normally but in the background do some job through linkClicked ignal/slot yet ???


    Qt Code:
    1. connect(this, SIGNAL(linkClicked(const QUrl &)), SLOT(linkIsClicked(const QUrl&)),Qt::DirectConnection);
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. this->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
    To copy to clipboard, switch view to plain text mode 

    Added after 1 23 minutes:


    Qt Code:
    1. void CLASS:linkClicked(const QUrl&) {
    2. load(url);
    3. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by migel; 26th September 2011 at 12:50.

  2. #2
    Join Date
    Jan 2014
    Qt products
    MacOS X Windows Android

    Lightbulb Re: QWebView linkClicked

    NOTE: The prior posted answer works great in simple circumstances. But not in all...

    webview->load( url ); will change the top level web view contents. This is no good if you use pages with iframes.

    If you have nested Iframes, and you click inside such a nesting, that simple load invocation will effectively move your nested frame to the top level and drop the parent frame out of the web view altogether.

    You need to load the url into the frame where the click occurred instead. In theory, you could do this here, as there a means to iterate through the frames in the webview and set their urls. The problem is knowing which frame contained the link. Unfortunately, the linkClicked signal only carries the destination url, but not the source of the click!

    There may in fact be a cleaner way, but I solved this by integrating javascript inside the web view with this linkClicked function. Hint: JS event listeners can capture link clicks, js postMessage() allows iframes to communicate with each other (even works CROSS DOMAIN), and js post message event objects have a source member which is a reference to the window/frame where the message originated.

    BWT, my solution works on ALL web pages (not just mine own) - so you can use the webview just like a normal browser with iframes displaying any site (or the way the webview works naturally - when you don't intercept these clicks).

Similar Threads

  1. Replies: 8
    Last Post: 3rd September 2013, 10:51
  2. linkCLicked Signal .
    By divanshu in forum Newbie
    Replies: 2
    Last Post: 5th July 2011, 07:28
  3. linkClicked signal
    By maston in forum Qt Programming
    Replies: 13
    Last Post: 7th September 2010, 21:26
  4. QWebView linkclicked and form submit
    By maddog_fr in forum Qt Programming
    Replies: 9
    Last Post: 8th August 2009, 21:03
  5. QWebPage::linkClicked() is only emitted once
    By Lykurg in forum Qt Programming
    Replies: 0
    Last Post: 20th November 2008, 13:56


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.