Results 1 to 8 of 8

Thread: Subclassing a QWebView

  1. #1
    Join Date
    Apr 2014
    Posts
    12
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Subclassing a QWebView

    Hi All,

    I need to solve the issue of navigating links within an iframe with a QWebView. After setting setLinkDelegationPolicy(QWebPage:elegateAllLinks), I check the link and then with the pages I'm not interested in then I open the link but if this link is in an iframe then the QWebView will open the link in the main frame and not the iframe. I know I need to subclass the QWebView and the closest example I get is here:

    http://www.qtcentre.org/threads/2299...nd-form-submit

    but I can't find a full code example ( .h and .cpp ) and my attempts produce linker errors. I guess a guru could set this up in less than 5 minutes but I've spent hours and hours on this

    As mentioned, I've seen a few solutions and at least one where somebody solves with JavaScript. I would appreciate help and I'm sure others would appreciate a small example. I don't know if this should have been posted in the advanced section?

    Thanks!!

  2. #2
    Join Date
    Apr 2014
    Posts
    12
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Subclassing a QWebView

    Am I posting to the wrong section? No answers or views

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Subclassing a QWebView

    What exactly is the problem? What errors are you getting?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Apr 2014
    Posts
    12
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Subclassing a QWebView

    Hi Wysota,

    Thanks for the reply. I have solved the linking errors but I need to know how to navigate pages within a iframe or frameset rather than the top main frame. As far as I understand then I am supposed to over ride navigation request in the subclassed QWebView something like:


    bool MyWebView::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, QWebPage::NavigationType type)
    {
    //Q_UNUSED(frame)
    if (type == NavigationTypeLinkClicked) {
    switch (d->linkPolicy) {
    case DontDelegateLinks:
    return true;

    case DelegateExternalLinks:
    if (WebCore::SchemeRegistry::shouldTreatURLSchemeAsLo cal(request.url().scheme()))
    return true;
    emit linkClicked(request.url());
    return false;

    case DelegateAllLinks:
    emit linkClicked(request.url());
    frame->load(QUrl("http://www.google.com/")); // Need to analyse first
    qDebug() << "LINK HAS BEEN CLICKED";
    return true;
    }
    }
    return true;
    }

    It is obviously wrong as I will get all sorts of errors such as:

    "error: use of undeclared identifier 'NavigationTypeLinkClicked'
    if (type == NavigationTypeLinkClicked) {
    ^"

    and

    "error: 'd' is a private member of 'QWebView'
    switch (d->linkPolicy) {"

    and

    "error: member access into incomplete type 'QWebViewPrivate'
    switch (d->linkPolicy) {
    ^
    ^"

    So I need an overview or quick example of how to cater for iframe navigation in a subclassed QWebView.

    FYI

    I have subclassed a QWebPag to specify a specific useragent and that works OK.

    I'm sure newbies would appreciate a full example of navigating within iframes as other solutions just state override the acceptNavigationRequest method to access the specific frame.

    Regards & Thanks

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Subclassing a QWebView

    I'm not sure what the problem is... The web frame is the method's parameter, you can access it there...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Apr 2014
    Posts
    12
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Subclassing a QWebView

    Wysota,

    First of all - thanks for your time, appreciated! I've made some progress.

    I have a subclassed QWebPage

    I have this:


    *****************
    bool MyCustomWebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, QWebPage::NavigationType type)
    {


    if (frame->parentFrame() != 0){
    if (type == NavigationTypeLinkClicked) {
    //frame->setUrl(request.url()); // THIS FAILS
    frame->setUrl(QUrl("http://www.google.co.uk")); // this works now and changes the URL in the frame
    // I Need to analyse the querystring parameters first
    }
    }
    qDebug() << "LINK HAS BEEN CLICKED"; // Just Checking where I am
    return true;
    }
    ******************

    Note this works with no setLinkDelegationPolicy(QWebPage:elegateAllLinks); NOT being set

    Notice that:

    frame->setUrl(request.url()); // THIS FAILS

    With

    error: member access into incomplete type 'const QNetworkRequest'
    frame->setUrl(request.url()); // Need to analyse first
    ^

    on the setUrl() method

    So

    a) I need to analyse the url

    b) I need to shut of that error

    Thanks in advance.

    Regards

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Subclassing a QWebView

    Qt Code:
    1. #include <QNetworkRequest>
    To copy to clipboard, switch view to plain text mode 

    BTW. Please use the [code] tags.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Apr 2014
    Posts
    12
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Subclassing a QWebView

    Wysota,

    Bingo! That does the job nicely. Thank you.

    Point taken on the code tags.

Similar Threads

  1. Replies: 8
    Last Post: 3rd September 2013, 09:51
  2. Subclassing QGraphicsItemGroup
    By onurozcelik in forum Qt Programming
    Replies: 0
    Last Post: 3rd May 2010, 07:41
  3. QGraphicsItem Subclassing
    By QbelcorT in forum Newbie
    Replies: 4
    Last Post: 19th November 2008, 01:06
  4. Subclassing QGraphicsView
    By sincnarf in forum Qt Programming
    Replies: 11
    Last Post: 27th August 2007, 19:36
  5. Subclassing
    By joseph in forum Newbie
    Replies: 1
    Last Post: 25th February 2006, 14:06

Tags for this Thread

Bookmarks

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.