Search code examples
qtraphaelqt5cross-compilingqtwebkit

Cross-compiled QtWebkit (Qt 5.2.1) cannot handle HTML pages using RaphaelJS


I cross-compiled Qt 5.2.1 (including ICU and QWebKit) on TI AM335x board (ARM-based).

Then I just prepared a simple QWebView-based application to show some HTML pages on my device.

I am able to do that for most pages, but I cannot completely show pages using RaphaelJS for some animations.

I have the suspect that the cross-compiled QtWebkit has some problems in handling this kind of javascript, and I would like to grab somehow out from QWebView the javascript error console, just to see where the problem is.

Maybe I am missing during cross-compilation? Some configure parameters? Please consider that the same application compiled against Qt Desktop works fine.

Can somebody help me?


Solution

  • Ok, I found the solution: I just subclassed QWebPage (providing the implementation of javaScriptConsoleMessage function) and assigned it to my QWebView through setPage().

    Here is my code:

    mywebpage.h:

    #ifndef MYWEBPAGE_H
    #define MYWEBPAGE_H
    
    #include <QWebPage>
    #include <QDebug>
    
    class MyWebPage : public QWebPage
    {
        Q_OBJECT
    public:
        explicit MyWebPage(QObject *parent = 0);
    
    signals:
    
    public slots:
    
    protected:
        virtual void javaScriptConsoleMessage(const QString &message, int lineNumber, const QString &sourceID);
    
    };
    
    #endif // MYWEBPAGE_H
    

    mywebpage.cpp:

    #include "mywebpage.h"
    
    MyWebPage::MyWebPage(QObject *parent) :
        QWebPage(parent)
    {
    }
    
    void MyWebPage::javaScriptConsoleMessage(const QString &message, int lineNumber, const QString &sourceID)
    {
        qDebug() << lineNumber << ": " << message;
    }
    

    and here is where I set the page of QWebView in my mainwindow.cpp (ui->webView is my QWebView):

    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        mwp = new MyWebPage(this);
        ui->webView->setPage(mwp);
    }
    

    Doing so all javascript error messages are printed out on console, and I've been able to find the point in RaphaelJS where the error is generated.