Use of <object> from javascript to Qt c++ ( example in this post )

i'm reading a book about Qt, there is an example that i don't understand, where we use an html page : i don't understand how all the <object> from the html page are "analyzed" by the c++ : i was looking at the BrowserWindow class, where the logic seems to happen : new BrowserWindow(url, new WebPage); but i did not find anything there...

Here's the code : first we have an html page with several <object> :

<object type="application/x-qt-plugin" classid="QLineEdit"
    id="nameEdit" height="30">Can't load QLineEdit plugin!</object>
<p>
<object type="application/x-qt-plugin" classid="MatrixWidget"
    id="leftMatrix" width="124" height="94" readonly="1">
Can't load MatrixWidget plugin!</object>

Then we have a WebPage class that is supposed to analyse the html : createPlugin responds to the type "application/x-qt-plugin" :

QObject* WebPage::createPlugin(const QString &classId,
        const QUrl&, const QStringList &parameterNames,
        const QStringList &parameterValues)
{
    QWidget *widget = 0;
    if (classId == "MatrixWidget") {
        widget = new MatrixWidget(view());
        int index = parameterNames.indexOf("readonly");
        if (index > -1)
            static_cast<MatrixWidget*>(widget)->setReadOnly(
                   static_cast<bool>(parameterValues[index].toInt()));
    }
    else { ...

And the main.cpp is :

QString url = QUrl::fromLocalFile(AQP::applicationPathOf() +
                                      "/matrixquiz.html").toString();
    BrowserWindow *browser = new BrowserWindow(url, new WebPage);

And the browserWindow class constructor is :

BrowserWindow::BrowserWindow(const QString &url, QWebPage *webPage,
                             QWidget *parent, Qt::WindowFlags flags)
    : QFrame(parent, flags)
{
    setFrameStyle(QFrame::Box|QFrame::Raised);

    webView = new QWebView;
    if (webPage)
        webView->setPage(webPage);
    load(url);

    createActions();
    createToolBar();
    createLayout();
    createConnections();
}

So, my question is : how do we check all the <object> in the html file?

Thanks for your help

Answers


When QtWebKit is parsing the webpage, if it finds an <object> tag with a type="application/x-qt-plugin" attribute, it will call the QWebPage::createPlugin function to try to create the plugin.

You don't have to explicitly check the object tags, QtWebKit does this all for you and converts it into the createPlugin call.


Need Your Help

Serializing a user-defined class in Python

python json serialization

got a question regarding serializing classes that I've defined. I have some classes like

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.