Nominate our 2022 Qt Champions!

How can we restrict QWebView not to download some js and css files.

  • Hi
    After QWebView::load() method I want to monitor loading files(js,css..) and cancel some of them. But I didn't find any event handler or event type. How can we do it?

  • Moderators


    You can do it in following way:

    • Create custom QNetworkAccessManager class by subclassing it.
    • Re-implement createRequest in it. It will be called everytime a new request is done by QWebview.
      Something like this:
    QNetworkReply *MyQNAM::createRequest ( Operation op, const QNetworkRequest & req, QIODevice * outgoingData){
            QNetworkReply *reply = QNetworkAccessManager::createRequest(op, req, outgoingData);
            qDebug() << req.url();
            return reply;
    • Get the current URL from QNetworkRequest req. You can filter according to it.
    • Finally set this custom QNetworkAccessManager to QWebView's page() using setNetworkAccessManager.

    Hope this helps...

Log in to reply