Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. QtWebkit : Capturing javascript errors

QtWebkit : Capturing javascript errors

Scheduled Pinned Locked Moved Qt WebKit
6 Posts 2 Posters 12.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    peterfhannon
    wrote on 19 Jun 2012, 13:06 last edited by
    #1

    Hello All,

    I'm just beginning with qt and qtwebkit so please forgive my newbness...

    Is it possible to capture javascript errors from qtwebkit?

    I have seen advice online that says to subclass QWebPage, and override javaScriptConsoleMessage.

    What I've done is to create a new HTML5 project in Qt Creator (which generates the Html5ApplicationViewerPrivate class), then create a new class, RRWebPage, and substitute that in place of QWebPage in Html5ApplicationViewerPrivate.

    In RRWebPage I have overridden javaScriptConsoleMessage, using qDebug to output a message and I have inserted a breakpoint into the function.

    I start debugging my application, I see some javascript alerts that I have put in, and then it hits a deliberate javascript error - but nothing happens... My breakpoint is not hit and nothing is logged... Other breakpoints are hit when the application is initializing so there is no problem with breakpoints.

    Can anyone shed any light on this please? Is this the correct way to capture javascript errors?

    I'm using Qt Creator 2.4.1, Build configuration Qt 4.8.1 for Desktop - MSVC2010 Debug

    Many thanks in advance,

    Peter

    1 Reply Last reply
    0
    • A Offline
      A Offline
      AcerExtensa
      wrote on 20 Jun 2012, 07:21 last edited by
      #2

      you mean javaScriptConsoleMessage is never called? maybe something wrong with function overriding or something else... I can only guess. If you can show us your code, it will help allot.

      God is Real unless explicitly declared as Integer.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        peterfhannon
        wrote on 20 Jun 2012, 08:25 last edited by
        #3

        Sorry yes, thats what I mean,

        Here is my subclass of QWebPage:

        RRWebPage.h
        @#ifndef RRWEBPAGE_H
        #define RRWEBPAGE_H

        #include <QWebPage>

        class RRWebPage : public QWebPage
        {
        Q_OBJECT
        public:
        explicit RRWebPage(QObject *parent = 0);

        void test();
        

        protected:
        void javaScriptConsoleMessage( const QString & message, int lineNumber, const QString & sourceID );

        signals:

        public slots:

        };

        #endif // RRWEBPAGE_H@

        RRWebPage.cpp
        @#include "rrwebpage.h"
        #include <QDebug>
        #include <QDate>

        RRWebPage::RRWebPage(QObject *parent) :
        QWebPage(parent)
        {
        }

        void RRWebPage::test()
        {
        //say hello!
        qDebug() << "Date:" << QDate::currentDate();
        }

        void RRWebPage::javaScriptConsoleMessage( const QString & message, int lineNumber, const QString & sourceID )
        {
        //do something!
        qDebug() << message << lineNumber << sourceID;
        }@

        Here is where I assign an instance of RRWebPage in html5applicationviewer.cpp:

        @NavigationControllerPrivate::NavigationControllerPrivate(QWidget *parent, QGraphicsWebView *webView)
        : m_webPage(0)
        , m_webWidget(0)
        , m_graphicsWebView(webView)
        , m_webNavigation(0)
        {
        Q_UNUSED(parent);
        m_graphicsWebView->setAcceptTouchEvents(true);
        m_webPage = new RRWebPage;
        m_graphicsWebView->setPage(m_webPage);
        m_webNavigation = new WebNavigation(m_graphicsWebView, m_webPage);
        m_webNavigation->setParent(m_graphicsWebView);
        }@

        Thanks for your help,

        Peter

        1 Reply Last reply
        0
        • A Offline
          A Offline
          AcerExtensa
          wrote on 20 Jun 2012, 08:58 last edited by
          #4

          Hm, simple test worked for me...
          So, no problem on QWebPage side...

          Just to be sure what you actually should get any message through javaScriptConsoleMessage, test it like this:

          connect to the webview signal loadFinished(bool), and in the connected slot execute following js:

          @<webview>->page()->mainFrame()->evaluateJavaScript("console.log('testing test');");@

          you should then see "testing test" in debug console or get breakpoint.

          God is Real unless explicitly declared as Integer.

          1 Reply Last reply
          0
          • P Offline
            P Offline
            peterfhannon
            wrote on 2 Jul 2012, 11:08 last edited by
            #5

            Hi again,

            Sorry for the delay, I got pulled onto another project but am resuming this now - 
            
            I have done as you requested, but javaScriptConsoleMessage does not get fired. I have verfied that 
            

            @<webview>->page()->mainFrame()->evaluateJavaScript("console.log('testing test');");@

            Is definitely running.
            

            Thanks,

            Peter

            1 Reply Last reply
            0
            • A Offline
              A Offline
              AcerExtensa
              wrote on 5 Jul 2012, 08:25 last edited by
              #6

              Ti be clear. if you run @evaluateJavaScript("console.log('testing test');");@ you see message "testing test" in your reimplemented javaScriptConsoleMessage function, right?

              God is Real unless explicitly declared as Integer.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved