Important: Please read the Qt Code of Conduct -

[Solved] How to get and change HTML from url before viewing in QWebView?

  • Dear all friends,

    I would like to get and change HTML from internet url before viewing in QWebView.
    When I try to load newly change HTML to set in QWebView after loadFinish() signal. It's OK.

    But when I try to change contents of Facebook page, & try to insert newly change HTML, it's not work.
    When I write out change HTML to a file, It's OK, open that file in browser also OK.

    That's why? I would like to know..
    So, Is it possible to get HTML, change them & return to QWebView before settings original HTML to QWebView?


  • What's the difference from the "previous post":

    To get html without QWebView. Do this:

    [ Edit: NOTE: QHttp is obsolete as pointed out by many others and shouldn't be used. Use the QNetworkManager instead. ]

    // constructor
    m_networkManager = new QNetworkAccessManager(this);

    connect(m_networkManager, SIGNAL(finished(QNetworkReply*)),
    this, SLOT(slotReplyFinished(QNetworkReply*)));


    //slotReplyFinished(QNetworkReply *response)
    QByteArray result;

    if (response->error() == QNetworkReply::NoError)
        result = response->readAll();
        QMessageBox::critical(this, tr("Error"), response->errorString());


    Obsolete method using QHttp.
    // In constructor
    m_http_buffer = new QTemporaryFile();
    m_http_client = new QHttp(this);

    // Http call
    QHttp::ConnectionMode mode = url.scheme().toLower() == "https" ? Http::ConnectionModeHttps : QHttp::ConnectionModeHttp;
    m_http_client->setHost(, mode, url.port() == -1 ? 0 : url.port());

    httpRequestId = m_http_client->get(url.path(),m_http_buffer);


    connect(m_http_client, SIGNAL(requestFinished(int,bool)),
    this, SLOT(slotHttpRequestFinished(int,bool)));

    // slotHttpRequestFinished
    if (id==httpRequestId)

        if (!error)
            // read response here
            disconnect(m_http_client, 0, this, 0);


    In header:
    private slots:
    void slotHttpRequestFinished(int id, bool error);

       QHttp   *m_http_client;
       int     httpRequestId;
       QTemporaryFile  *m_http_buffer;


  • Dear friend,

    Thanks for your reply

    I want to change some data on HTML requested from internet.
    It's like Firefox plug-in which change some HTML & is shown in main browser to user.
    When I insert just some html text instead of change function, It's also work.

    But, my change function is also work, I tested with changed data to output file.
    That output file can be opened & show correctly in FF for my changes.

    I don't understand why my browser can't show these changes. It's just some Unicode character corrections. I recompile Qt lib for these unicode support.


  • Okay :) If solved.. could mark as solved in title?

  • NOTE: Do not use QHttp this class is deprecated! Use QNetworkAccessManager instead!!

Log in to reply